我正在寻找一种方法,使多个上下文抽屉在颤栗。到目前为止,我已经有了两个抽屉-一个在左边,一个在右边。然而,我真正想要完成的是通过右上角的动作按钮拥有多个上下文抽屉菜单。
由于默认情况下有两个抽屉的限制,我尝试通过编程“交换”endDrawer。我无法做到这一点,因为抽屉小部件是“最终”。因此,接下来的解决方案可能是重建抽屉的内部结构。但我不知道该怎么做,因为我还是新手。
所以我的问题是:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: [
// Menu 1
Builder(builder: (context) => IconButton(icon: Icon(Icons.filter_alt),onPressed: () {
ScaffoldState scaffoldState = Scaffold.of(context);
// I'm trying to rebuild the drawer here
//scaffoldState.widget.drawer.build...
scaffoldState.openEndDrawer();
},),),
// Menu 2
Builder(builder: (context) => IconButton(icon: Icon(Icons.filter_alt),onPressed: () {
ScaffoldState scaffoldState = Scaffold.of(context);
// I'm trying to rebuild the drawer here
//scaffoldState.widget.drawer.build...
scaffoldState.openEndDrawer();
},),),
// Menu 3
Builder(builder: (context) => IconButton(icon: Icon(Icons.filter_alt),onPressed: () {
ScaffoldState scaffoldState = Scaffold.of(context);
// I'm trying to rebuild the drawer here
//scaffoldState.widget.drawer.build...
scaffoldState.openEndDrawer();
},),),
]
//actions: [Icon(Icons.notifications)],
),
drawer: Drawer(
child: Drawer(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Left Menu Item 1'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Left Menu Item 2'),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
),
endDrawer: Drawer(
child: Drawer(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header 2'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Right Menu Item 1'),
onTap: () {
Navigator.pop(context);
// Update the state of the app.
// ...
},
),
ListTile(
title: Text('Right Menu Item 2'),
onTap: () {
Navigator.pop(context);
// Update the state of the app.
// ...
},
),
],
),
),
),
body: Center(),
);
}发布于 2021-05-29 12:26:12
我是个新手,但我也面临着同样的问题。找不到办法做3个抽屉,但找到了一个替代方案,可能是或不可能是你想要的。
showModalBottomSheet从底部打开一张床单(很像抽屉),你可以随心所欲地添加这些东西。您可以查看文档这里。
https://stackoverflow.com/questions/65443501
复制相似问题