Flutter navigation drawer hamburger icon color change
Asked Answered
M

9

90

Hamburger icon color of navigation drawer is not changing. Its black by default. I want to change the this icon color in flutter, I am stuck, help me to change this icon color. here is my code.

class Test extends StatefulWidget {
@override
_TestState createState() => new _TestState();
}

class _TestState extends State<Test> {


    @override
    Widget build(BuildContext context) {
    return new Scaffold(

    drawer: new Drawer(),
    appBar: new AppBar(
    title: new Text("Navigation Drawer")
        ),
       ),
     );
    }
 }
Merrygoround answered 29/5, 2018 at 8:56 Comment(0)
B
236

The iconTheme property of the AppBar widget is used to specify the styling for the leading icon, which is typically the menu icon.

By setting IconThemeData(color: Colors.green), the color of the leading icon in the app bar is changed to green.

@override
Widget build(BuildContext context) {
  return Scaffold(
    drawer: Drawer(),
    appBar: AppBar(
      title: Text("Navigation Drawer"),
      iconTheme: IconThemeData(color: Colors.green),
    ),
  );
}

You can also check other solutions here.

Bebe answered 29/5, 2018 at 9:20 Comment(1)
This method does not work when enabling useMaterial3 in Flutter. It works without Material 3 enabledPruchno
L
16

To change the color of icons in your Flutter app’s AppBar and other parts of the UI:

1. Using Theme Widget: This sets the primary icon theme color to red for all icons.

Theme(data: ThemeData(primaryIconTheme: IconThemeData(color: Colors.red)), child: Scaffold())

Directly Setting Icon Color: This changes the color of the menu icon in the AppBar to red.

appBar: AppBar(
  leading: IconButton(icon: Icon(Icons.menu, color: Colors.red), onPressed: () {}),
),
Lazuli answered 22/12, 2018 at 11:42 Comment(0)
P
5

To change color of your icon use this

  @override
  Widget build(BuildContext context) {
   return new MaterialApp(
   home: new Scaffold(
    appBar: AppBar(title: new Text('List view example'),
      leading: new Icon(Icons.menu,color: Colors.green,),
   ),
),
 );
 }

Icon(Icons.menu,color: Colors.green,) define color inside Icon

Paraplegia answered 14/12, 2018 at 19:12 Comment(0)
P
5

Use iconTheme in Appbar like this:

Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text("App Bar"),
          iconTheme: IconThemeData(color: Colors.black),
        ),
        drawer: Drawer(),
      );
}
Presentational answered 16/6, 2021 at 11:27 Comment(2)
This is, once again, what the other answer says. What's new?Tricky
Copied from https://mcmap.net/q/235061/-flutter-navigation-drawer-hamburger-icon-color-changeTricky
T
3

This is the only solution to make the button clickable otherwise you need to openDrawer onTap.

AppBar(
            iconTheme: const IconThemeData(
              size: 40, //change size on your need
              color: Colors.black, //change color on your need
            ),
    ),
Telesis answered 23/6, 2022 at 9:35 Comment(0)
O
3

Using The iconTheme for Appbar is not currently working with useMaterial3 = true, And all these answers defined a leading icon for the Appbar without telling how to implement it's onPress behavior, So the best way to change the Drawers icon or it's color is this :

Declare the key for Scaffold :

final scaffoldKey = GlobalKey<ScaffoldState>();

And apply it to Scaffold:

Scaffold(
     key: scaffoldKey,
     drawer: Drawer()
)

Then , Apply the drawer icon like below with click action:

AppBar(
  title: Text("My AppBar"),
  leading: IconButton(
      icon: Icon(Icons.person),
      onPressed: (){
        if(scaffoldKey.currentState!.isDrawerOpen){
              scaffoldKey.currentState!.closeDrawer();
              //close drawer, if drawer is open
        }else{
              scaffoldKey.currentState!.openDrawer();
              //open drawer, if drawer is closed
        }
      },
  ),
)
Oversold answered 4/12, 2022 at 12:12 Comment(0)
T
1

you can change drawer icon color by Add iconTheme to your AppBar:-

@override
Widget build(BuildContext context) {
  return Scaffold(
    drawer: Drawer(),
    appBar: AppBar(
      title: Text("Drawer"),
      iconTheme: IconThemeData(color: Colors.black),
    ),
  );
}
Tandy answered 18/2 at 22:9 Comment(1)
Is n't this already given by the accepted answer, but also some others. What is new?Tricky
C
0

You can change it from main.dart easily this way-

return MaterialApp(
      title: 'XYZ',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        appBarTheme: AppBarTheme(
          iconTheme: IconThemeData(color: Colors.black),
          actionsIconTheme: IconThemeData(color: Colors.blue),
          backgroundColor: theme.backgroundColor,
          elevation: 0,
        ),

      ),
Codycoe answered 15/11, 2022 at 10:58 Comment(0)
O
0

iconTheme: IconThemeData(color: Colors.red) With Adding This line you will able to get the desired output

Orotund answered 17/2 at 13:44 Comment(1)
What is new compared to the accepted answer, but others also?Tricky

© 2022 - 2024 — McMap. All rights reserved.