如何修改Flutter中Drawer图标的颜色?当前为白色需改为黑色
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

