You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Flutter中Drawer图标的颜色?当前为白色需改为黑色

How to Change Drawer Icon Color from White to Black in Flutter

Hey there! Changing the Drawer (hamburger) icon color is straightforward once you know where to tweak the settings. Here are a few reliable methods tailored to your needs:

Method 1: Use AppBar's iconTheme Property

This is the simplest fix if you’re using an AppBar with your Scaffold. Just set the color property inside iconTheme to black, and it’ll automatically apply to the default drawer icon.

Here’s how to integrate this with your existing Drawer code:

Scaffold(
  appBar: AppBar(
    title: Text('Your App Title'),
    // Adjust the drawer icon color here
    iconTheme: IconThemeData(color: Colors.black),
  ),
  drawer: Drawer(
    child: ListView(
      children: <Widget>[
        UserAccountsDrawerHeader(
          accountName: Text('test'),
          accountEmail: Text('test'),
        ),
        // Add additional drawer items here
      ],
    ),
  ),
);

Method 2: Customize the Leading Widget

If you want more control (like using a different icon or adding padding), replace the default leading widget with a custom IconButton:

Scaffold(
  appBar: AppBar(
    title: Text('Your App Title'),
    leading: IconButton(
      icon: Icon(Icons.menu, color: Colors.black), // Define your icon and color
      onPressed: () => Scaffold.of(context).openDrawer(),
    ),
  ),
  drawer: Drawer(
    child: ListView(
      children: <Widget>[
        UserAccountsDrawerHeader(
          accountName: Text('test'),
          accountEmail: Text('test'),
        ),
      ],
    ),
  ),
);

Method 3: Apply App-Wide Theme Change

If you want the black drawer icon to be consistent across your entire app, adjust the ThemeData in your root MaterialApp:

MaterialApp(
  theme: ThemeData(
    appBarTheme: AppBarTheme(
      iconTheme: IconThemeData(color: Colors.black),
    ),
  ),
  home: YourHomeScreen(),
);

Pick the method that fits your use case—quick one-off change, custom icon setup, or app-wide consistency.

内容的提问来源于stack exchange,提问作者Atakan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 12:07:35