
您可以使用ExpandablePanelList来执行展开和折叠视图。使用expandingCallback保持活动状态以执行展开或折叠。这是工作示例
class TestExpandableView extends StatefulWidget { @override _TestExpandableViewState createState() => _TestExpandableViewState();}class _TestExpandableViewState extends State<TestExpandableView> { int _activeMeterIndex; @override Widget build(BuildContext context) { return Container( child: new ListView.builder( itemCount: 2, itemBuilder: (BuildContext context, int i) { return Card( margin: const EdgeInsets.fromLTRB(10.0, 15.0, 10.0, 0.0), child: new ExpansionPanelList( expansionCallback: (int index, bool status) { setState(() { _activeMeterIndex = _activeMeterIndex == i ? null : i; }); }, children: [ new ExpansionPanel(isExpanded: _activeMeterIndex == i,headerBuilder: (BuildContext context, bool isExpanded) =>new Container( padding: const EdgeInsets.only(left: 15.0), alignment: Alignment.centerLeft, child: new Text( 'list-$i', )),body: new Container(child: new Text('content-$i'),),), ], ), ); }), ); }}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)