如何在应用程序启动时打开抽屉?

问题描述 投票:0回答:1

我的应用程序加载到起始页面上,并且在加载页面时,我需要自动显示抽屉菜单,如何打开此菜单?在void main()中,有这个:

new MaterialApp(
      initialRoute: '/page',
      builder: (context, widget) {

        return new Padding(
          child: widget,
          padding: new EdgeInsets.only(bottom: 10.0),
        );
flutter drawer
1个回答
0
投票
void main() => runApp(MaterialApp(home: AppPage()));

class AppPage extends StatefulWidget {
  @override
  _AppPageState createState() => _AppPageState();
}

class _AppPageState extends State<AppPage> {
  final GlobalKey<ScaffoldState> _key = GlobalKey();

  @override
  void initState() {
    super.initState();
    Timer.run(() => _key.currentState.openDrawer());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _key,
      appBar: AppBar(),
      drawer: Drawer(),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.