expansiontile list

Posted pp-pping

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了expansiontile list相关的知识,希望对你有一定的参考价值。

代码:

import ‘package:flutter/material.dart‘;

class ExpansionPaneListDemo extends StatefulWidget {


@override
_ExpansionPaneListDemoState createState() => _ExpansionPaneListDemoState();
}

class _ExpansionPaneListDemoState extends State<ExpansionPaneListDemo> {


List<int> mlist;//
List<ExpandStateBean> expandStateList;

_ExpansionPaneListDemoState(){//初始化
mlist = new List();
expandStateList = new List();
for (var i = 0; i < 10; i++) {
mlist.add(i);
expandStateList.add(ExpandStateBean(i, false));
}
}


_setCurrentIndex(int index,isExpand){
setState(() {
expandStateList.forEach((item){
if (item.index == index) {
item.isOpen = !isExpand;
}
});
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(‘expansion List‘)),
body: SingleChildScrollView(//

child: ExpansionPanelList(//必须放在滚动控件下
expansionCallback: (index,bol){
_setCurrentIndex(index, bol);
},
children: mlist.map((index){
return ExpansionPanel(
headerBuilder: (context,isExpanded){
return ListTile(//没展开的数据
title: Text(‘No.$index‘),
);
},
body: ListTile(//展开的数据
title: Text(‘xx $index‘),
),
isExpanded: expandStateList[index].isOpen
);

}).toList(),
),

),
);
}
}


class ExpandStateBean{
var isOpen;
var index;
ExpandStateBean(this.index,this.isOpen);

}

以上是关于expansiontile list的主要内容,如果未能解决你的问题,请参考以下文章

修改默认的 ExpansionTile 子项垂直填充 Flutter

expansiontile 打开关闭楼层

Flutter:ExpansionTile 示例

ListView 内的 ExpansionTile - 页面不滚动

如何在 Flutter 中折叠其他 ExpansionTile 元素

Flutter之ExpansionTile组件