个人认为第一种好看,但是两种方式都不能更改‘专业列表’部分背景颜色,让我很头疼
第一种:ExpansionTile
class ExpansionTileDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ExpansionTile(
title:Text('专业列表'),
leading:Icon(Icons.list),
children:<Widget>[
ListTile(
title:Text('title'),
subtitle:Text('subtitle'),
),
ListTile(
title:Text('title'),
subtitle:Text('subtitle'),
),
ListTile(
title:Text('title'),
subtitle:Text('subtitle'),
),
ListTile(
title:Text('title'),
subtitle:Text('subtitle'),
),
],
);
}
}
第二种:ExpansionPanelList
外层必须包裹SingleChildScrollView
// 引入部分
ExpansionTileDemo(),
SingleChildScrollView(
child: Container(
child: BuildExpansionPanelList(),
),
),
class BuildExpansionPanelList extends StatefulWidget {
@override
_BuildExpansionPanelListState createState() => _BuildExpansionPanelListState();
}
class _BuildExpansionPanelListState extends State<BuildExpansionPanelList> {
// List<bool> dataList = List.generate(20, (index) => false).toList();
List<bool> dataList = List.generate(1, (index) => false).toList();
@override
Widget build(BuildContext context) {
return Container(
child:ExpansionPanelList(
elevation: 0,
expansionCallback: (index, isExpanded) {
setState(() {
dataList[index] = !isExpanded;
});
},
children: dataList.map((value) {
return ExpansionPanel(
isExpanded: value,
canTapOnHeader:true,
headerBuilder: (context, isExpanded) {
return Container(
child:ListTile(
title: Text('专业列表'),
),
);
},
body: Container(
// color:Colors.green,
child:ListView.builder(
shrinkWrap:true,
physics:NeverScrollableScrollPhysics(),
itemCount:subMsgList.length,
itemBuilder: (BuildContext context,int index){
return Container(
margin:EdgeInsets.fromLTRB(10,0,10,0),
height:40,
child:Row(
children:<Widget>[
Text(subMsgList[index]['subName'],style:TextStyle(color:Color.fromRGBO(71, 80, 133, 1.0),)),
Expanded(
child:SizedBox(),
),
Container(
width:80,
height:22,
padding:EdgeInsets.fromLTRB(0,3,0,3),
decoration:new BoxDecoration(
borderRadius:BorderRadius.all(Radius.circular(4.0)),
color:Colors.blue,
),
child:Center(
child:Text(subMsgList[index]['subKind'],style:TextStyle(color:Colors.white,fontSize:12)),
),
),
Container(
margin:EdgeInsets.fromLTRB(10,0,10,0),
padding:EdgeInsets.fromLTRB(2,3,2,3),
decoration:new BoxDecoration(
borderRadius:BorderRadius.all(Radius.circular(4.0)),
color:Colors.blue,
),
child:Text(subMsgList[index]['kind'],style:TextStyle(color:Colors.white,fontSize:12)),
),
],
),
);
}
),
),
);
}).toList(),
),
);
}
}