如何在抽屉中添加多级可扩展菜单
我试图找到一种方法来向这个抽屉添加子菜单并点击折叠它们。 即:我想用一个标题和 3 个副标题来调用这个小部件,例如:
- Flutter
- 列出项目
- 列出项目
- 列出项目
任何帮助将不胜感激。 谢谢。
class DrawerListTile extends StatelessWidget {
const DrawerListTile({
Key key, @required this.title,@required this.svgSrc,@required this.press,
}) : super(key: key);
final String title,svgSrc;
final VoidCallback press;
@override
Widget build(BuildContext context) {
return ListTile(
onTap:press,
horizontalTitleGap: 0.0,
leading: SvgPicture.asset(
svgSrc,
color: Colors.black,
height:16,
),
title:Text(
title,
style: TextStyle(color: Colors.black),
),
trailing: Icon(Icons.arrow_drop_down,size:15),
);
}
}
I was trying to find a way to add sub-menus to this drawer and to collapse them on tap.
Ie: I want to call this widget with a title and 3 subtitles like :
- Flutter
- List item
- List item
- List item
Any help would be appreciated.
Thank you.
class DrawerListTile extends StatelessWidget {
const DrawerListTile({
Key key, @required this.title,@required this.svgSrc,@required this.press,
}) : super(key: key);
final String title,svgSrc;
final VoidCallback press;
@override
Widget build(BuildContext context) {
return ListTile(
onTap:press,
horizontalTitleGap: 0.0,
leading: SvgPicture.asset(
svgSrc,
color: Colors.black,
height:16,
),
title:Text(
title,
style: TextStyle(color: Colors.black),
),
trailing: Icon(Icons.arrow_drop_down,size:15),
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 ExpansionTile 小部件就是您正在寻找的。
这将提供一个在点击时隐藏/显示子图块的图块。您还可以使用
trailing
参数指定自定义尾随图标。下面是从文档中提取的一个简单示例。I think the ExpansionTile widget is what you're looking for.
This would provide a tile that hides/shows the child tiles when it's tapped. You can also specify a custom trailing icon with the
trailing
parameter. Below is a quick example pulled from the docs.