【问题标题】:How to change the drawer color of the Scaffold widget如何更改 Scaffold 小部件的抽屉颜色
【发布时间】:2020-04-16 23:47:04
【问题描述】:

如何更改打开脚手架小部件抽屉菜单的按钮(图标)的颜色?

return Scaffold(
  backgroundColor: Color(0xffc2c2c2),
  drawer: Drawer(
    ...
    child: ListView(
      padding: EdgeInsets.zero,
      children: <Widget>[
        DrawerHeader()


           ...

没有像 iconColor 或 backgroundColor 这样的选项。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您可以通过执行以下操作更改 appBar 中图标的颜色:

    return Scaffold(
            appBar: AppBar(
              title: const Text('Drawer Demo'),
              iconTheme: IconThemeData(color: Colors.black), 
            ),
    

    https://api.flutter.dev/flutter/material/AppBar-class.html

    https://api.flutter.dev/flutter/material/AppBar/iconTheme.html

    【讨论】:

      【解决方案2】:

      使用AppBariconTheme 属性。例如,这是我的AppBar 代码:

      return AppBar(
        elevation: 0,
        centerTitle: true,
        brightness: DynamicTheme.of(context).brightness,
        backgroundColor: Theme.of(context).primaryColor,
        actions: actions == null ? [] : actions,
        title: Text(
          title,
          style: GoogleFonts.openSans(
            fontWeight: FontWeight.w600,
            textStyle: TextStyle(
              color: Theme.of(context).textTheme.body1.color,
            ),
          ),
        ),
        iconTheme: IconThemeData(color: Colors.black),
        leading: leading,
      );
      

      在 Scaffold 中,有一个 appBar 属性,以防您不知道。它还取决于brightness 属性,所以如果它是黑暗的,图标将是白色的,等等。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-22
        • 2020-05-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多