MENU

Flutter中Drawer,通过事件打开Drawer,隐藏左右侧功能按钮

September 27, 2022 • flutter

事件打开 Drawer

1.在组件中定义一个 GlobalKey:

  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

2.添加 key 参数:

return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        ...

3.通过事件触发:

 onTap: () {
                  _scaffoldKey.currentState?.openEndDrawer();
                },

隐藏顶部左右侧按钮

return Scaffold(
   
      appBar: AppBar(
        title: const Text('productList'),
        actions: [Text('')], //右侧隐藏
        leading: Text(''), //左侧隐藏
      ),