简体   繁体   English

Flutter 更改 Scaffold 抽屉图标

[英]Flutter change Scaffold drawer icon

I would like to change the default Scaffold drawer icon (hamburger icon).我想更改默认的 Scaffold 抽屉图标(汉堡包图标)。

I tried to add a key to the Scaffold widget and a leading icon, but it didn't work form me:我尝试向 Scaffold 小部件和前导图标添加一个键,但它对我不起作用:

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        /* ... */
        leading: IconButton(
          icon: Icon(Icons.person),
          onPressed: () {
            _scaffoldKey.currentState.openDrawer();
          },
        ),
      ),
      drawer: Drawer(
        /* ... */
      ),
      /* ... */
    );
  }
}

How can I change the drawer icon?如何更改抽屉图标?

I accomplished this by adding a leading icon wrapped by a Builder widget (the key was not needed):我通过添加一个由 Builder 小部件包装的前导图标来实现这一点(不需要密钥):

return Scaffold(
  appBar: AppBar(
    /*...*/
    leading: Builder(
      builder: (BuildContext context) {
        return IconButton(
          icon: const Icon(Icons.person),
          onPressed: () { Scaffold.of(context).openDrawer(); },
        );
      },
    ),
   /*...*/
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM