83

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")
        ),
       ),
     );
    }
 }
Ammy Kang
  • 11,283
  • 21
  • 46
  • 68

7 Answers7

220

Add iconTheme to your AppBar

@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.

Phuc Tran
  • 7,555
  • 1
  • 39
  • 27
13

You can also use following in Theme's data property

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

Or

appBar: AppBar(
  leading: IconButton(
    icon: Icon(Icons.menu, color: Colors.red), // set your color here
    onPressed: () {},
  ),
),
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
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

kishan verma
  • 984
  • 15
  • 17
4

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(),
      );
}
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
            ),
    ),
2

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
        }
      },
  ),
)
ParSa
  • 1,118
  • 1
  • 13
  • 17
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,
        ),

      ),
Tanvir Ahmed
  • 564
  • 6
  • 13