美文网首页
flutter折叠面板ExpansionPanel

flutter折叠面板ExpansionPanel

作者: wrootlflvl | 来源:发表于2019-07-11 09:57 被阅读0次
class ExpansionPanelDemo extends StatefulWidget {
  @override
  _ExpansionPanelDemoState createState() => _ExpansionPanelDemoState();
}

class _ExpansionPanelDemoState extends State<ExpansionPanelDemo> {
  bool _isExpanded = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('ExpansionPanelDemo'), elevation: 0.0,),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment:  MainAxisAlignment.center,
          children: <Widget>[
            ExpansionPanelList( // 点击折叠按钮实现面板的伸缩
              expansionCallback: (int panelIndex, bool isExpanded) {
                setState(() {
                  _isExpanded = !isExpanded;
                });
              },
              children: [
                ExpansionPanel(
                  headerBuilder: (BuildContext context, bool isExpanded) {
                    return Container(
                      padding: EdgeInsets.all(16.0),
                      child: Text('Panel A', style: Theme.of(context).textTheme.title,),
                    );
                  },
                  body: Container(
                    padding: EdgeInsets.all(16.0),
                    width: double.infinity,
                    child: Text('Content for Panel A.'),
                  ),
                  isExpanded: _isExpanded, // 设置面板的状态,true展开,false折叠
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

相关文章

网友评论

      本文标题:flutter折叠面板ExpansionPanel

      本文链接:https://www.haomeiwen.com/subject/rpfrkctx.html