How to change the appBar back button color
I cannot figure out how to change the appBar's automatic back button to a different color. it's under a scaffold and I've tried to research it but I can't wrap my head around it.
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
title: Image.asset(
'images/.jpg',
fit: BoxFit.fill,
),
centerTitle: true,
),
Solution 1:
You have to use the iconTheme
property from the AppBar , like this:
appBar: AppBar(
iconTheme: IconThemeData(
color: Colors.black, //change your color here
),
title: Text("Sample"),
centerTitle: true,
),
Or if you want to handle the back button by yourself.
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.of(context).pop(),
),
title: Text("Sample"),
centerTitle: true,
),
Even better, only if you want to change the color of the back button.
appBar: AppBar(
leading: BackButton(
color: Colors.black
),
title: Text("Sample"),
centerTitle: true,
),
Solution 2:
you can also override the default back arrow with a widget of your choice, via 'leading':
leading: new IconButton(
icon: new Icon(Icons.arrow_back, color: Colors.orange),
onPressed: () => Navigator.of(context).pop(),
),
all the AppBar widget does is provide a default 'leading' widget if it's not set.
Solution 3:
It seemed to be easier to just create a new button and add color to it, heres how i did it for anyone wondering
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: BackButton(
color: Colors.black
),
Solution 4:
You can also set leading icon color globally for the app
MaterialApp(
theme: ThemeData(
appBarTheme: AppBarTheme(
iconTheme: IconThemeData(
color: Colors.green
)
)
)
)
Solution 5:
Set back button color globally
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
appBarTheme: AppBarTheme(
backgroundColor: Colors.white,
iconTheme: IconThemeData(color: Colors.black), // set backbutton color here which will reflect in all screens.
),
),
home: LoginScreen(),
);
Also,
To change SliverAppBar
SliverAppBar(
iconTheme: IconThemeData(
color: Colors.white, //change your color here
),