【发布时间】:2021-10-05 19:51:15
【问题描述】:
【问题讨论】:
标签: flutter drop-down-menu flutter-layout dropdown
【问题讨论】:
标签: flutter drop-down-menu flutter-layout dropdown
您可以通过使用ExpansionPanelList 小部件来完成您正在寻找的东西:
https://api.flutter.dev/flutter/material/ExpansionPanelList-class.html
【讨论】:
试试下面的代码希望它对你有帮助我已经尝试过与你的要求相同的使用 ExpansionPanel 小部件
为真假声明声明布尔变量
bool? isExpanded;
bool _expanded = false;
声明在下拉列表中显示您的列表小部件
List<String> data = [
"Administrative Assistance",
"Autonomous Driving",
"Brand",
"Business Intelligence",
"Customer Service",
];
声明你的小部件
Column(
children: [
Container(
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
),
child: ExpansionPanelList(
animationDuration: Duration(
milliseconds: 1000), //change duration on your need here
children: [
ExpansionPanel(
headerBuilder: (context, isExpanded) {
return ListTile(
title: Text(
'Department',
style: TextStyle(color: Colors.black),
),
);
},
body: Column(
children: [
Divider(
height: 1,
color: Colors.green,
),
ListView.separated(
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(
data[index],
),
);
},
separatorBuilder: (context, index) => Divider(
height: 1,
color: Colors.black,
),
itemCount: data.length),
],
),
isExpanded: _expanded,
canTapOnHeader: true,
),
],
dividerColor: Colors.grey,
expansionCallback: (panelIndex, isExpanded) {
_expanded = !_expanded;
setState(() {});
},
),
),
],
),
【讨论】: