利用 ExpandionTile 可以实现可以展开收起的列表。
这是里面的构造方法:
const ExpansionTile({
Key? key,
this.leading,//标题左侧展示
required this.title,//展示标题的widget
this.subtitle,
this.onExpansionChanged,//展开收起回调函数
this.children = const <Widget>[],//展开是显示的内容wedget
this.trailing,//标题右侧展示的widget
this.initiallyExpanded = false,//默认展开/收起
this.maintainState = false,
this.tilePadding,//标题右侧展示wigget
this.expandedCrossAxisAlignment,
this.expandedAlignment,
this.childrenPadding,
this.backgroundColor,
this.collapsedBackgroundColor,
this.textColor,
this.collapsedTextColor,
this.iconColor,
this.collapsedIconColor,
this.controlAffinity,
})
代码示例如下:
class MyApp extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Tabbed AppBar'),
),
body: getLv(context),
),
);
}
Widget getLv(BuildContext context) {
return Center(
child: ListView(children: <Widget>[
ExpansionTile(
title: const Text('Sublist'),
backgroundColor: Theme.of(context).accentColor.withOpacity(0.025),
initiallyExpanded: false,
children: const <Widget>[
ListTile(title: Text('One')),
ListTile(title: Text('Two')),
ListTile(title: Text('Free')),
ListTile(title: Text('Four'))
]),
ExpansionTile(
title: const Text('Sublist'),
backgroundColor: Theme.of(context).accentColor.withOpacity(0.025),
initiallyExpanded: false,
children: const <Widget>[
ListTile(title: Text('One')),
ListTile(title: Text('Two')),
ListTile(title: Text('Free')),
ListTile(title: Text('Four'))
]),
]),
);
}
}

2317

被折叠的 条评论
为什么被折叠?



