我想在我的flutter应用程序中添加后退按钮和汉堡包图标?这在iOS中非常有用,特别是在深度导航中快速导航到根页面。
您可能想要这样做:(在您的Scaffold
中)
appBar: AppBar(leading: Row(children:[FirstIcon(), SecondIcon(),],),
要打开Drawer
,您必须这样做:(在您的小部件的build
方法中):
/// create a Drawer key
final GlobalKey<ScaffoldState> _drawerKey = GlobalKey();
/// this function opens the drawer
void _openDrawer()=>_drawerKey.currentState.openDrawer();
/// then use it to open the Drawer
Scaffold(appBar: AppBar(leading: Row(children: <Widget>[IconButton(onPressed:_openDrawer, icon:Icon(Icons.hamburger,),), SecondIcon(),],),
),);
编辑:不要忘记将_drawerKey
添加到Drawer
中。是这样的:Drawer(key: _drawerKey, child: YourWidget(),),