ExpansionPanelList不扩展也不折叠ExpansionPanel

时间:2019-04-25 01:38:15

标签: dart flutter

我正在ExpansionPanel()中使用Tab() s。 ExpansionPanel()正确显示。但是它的isExpanded属性永远不会改变(是的,我有一行应该更改它),因此无法折叠或展开ExpansionPanel()

我尝试使用Expansion Panel List in FlutterCan't create ExpansionPanelList with Items in Flutter的答案,但没有一个起作用。

我也尝试遵循Flutter ExpansionPanel Demo,但没有成功。

// ...

class _PlaceExpandedPanelItem {
  _PlaceExpandedPanelItem({this.isExpanded, this.header, this.body, this.icon});

  bool isExpanded;
  final String header;
  final Widget body;
  final Icon icon;
}

class _HomePage extends State<HomePage> with SingleTickerProviderStateMixin{
  int _selectedIndex = 0;

  TabController _tabController;

  List<_PlaceExpandedPanelItem> _placeExpandedPanelItems = <_PlaceExpandedPanelItem>[
    _PlaceExpandedPanelItem(
      isExpanded: true,
      header: 'Header',
      body: Column(
        children: <Widget>[
          Text('Body')
        ],
      ),
      icon: null
    ),
    _PlaceExpandedPanelItem(
        isExpanded: false,
        header: 'Header',
        body: Text('Body'),
        icon: null
    ),
  ];

  List<Tab> _allTabs;

  @override
  void initState() {
    super.initState();
    _allTabs = <Tab>[
      Tab(
          child: Container(
            child: ListView(
              children: <Widget>[
                new ExpansionPanelList(
                  expansionCallback: (int index, bool isExpanded) {
                    setState(() {
                      _placeExpandedPanelItems[index].isExpanded = !_placeExpandedPanelItems[index].isExpanded;
                    });
                  },
                  children: _placeExpandedPanelItems.map((_PlaceExpandedPanelItem _placeExpandedPanelItem){
                    return ExpansionPanel(
                      headerBuilder: (BuildContext context, bool isExpanded) {
                        return Text(_placeExpandedPanelItem.isExpanded.toString());
                      },
                      isExpanded: _placeExpandedPanelItem.isExpanded,
                      body: _placeExpandedPanelItem.body,
                    );
                  }).toList(),
                )
              ],
            ),
            margin: EdgeInsets.all(16.0),
          )
      ),
      Tab(
        child: Text('Tab 2'),
      ),
      Tab(
        child: Text('Tab 3'),
      ),
    ];

    _tabController = TabController(vsync: this, length: _allTabs.length);
  }

// ...

我希望ExpansionPanel()会在调用expansionCallback时折叠或展开,但不会折叠或展开。

0 个答案:

没有答案