In main.dart
void main() {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.black.withOpacity(0), //top bar color
statusBarIconBrightness: Brightness.dark, //top bar icons
systemNavigationBarColor: Colors.black, //bottom bar color
systemNavigationBarIconBrightness: Brightness.light, //bottom bar icons
),
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
//primaryColor: Color.fromRGBO(113, 201, 206, 1),
fontFamily: 'Montserrat',
textTheme: TextTheme(
headline: TextStyle(
fontSize: 40,
fontWeight: FontWeight.w500,
),
title: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 16,
),
body1: TextStyle(
fontSize: 12,
),
),
),
home: Test(),
routes: {
MainScreen.routeName: (context) => MainScreen(),
},
);
}
}
I am using the above code to change the color of the status bar, statusBarIconBrightness: Brightness.dark
has no effect.
It becomes black but after a few seconds it switches back to `Brightness.light'.
What's wrong?
Running on Android Emulator.
I don't want to have appBar
int the Test()
widget.
As of Flutter 2.4.*, AppBar brightness is deprecated. To achieve status bar brightness, add a systemOverlayStyle to your AppBar as I have highlighted below. If you wish to apply dark status bar icons on the entire app, add an appBarTheme to your MaterialApp theme as shown in the following code. Your MaterialApp widget is on the main.dart file;
The color of the status bar can be set by passing a Color as the statusBarColor argument. To make the status bar looks transparent, you can set the opacity of the color. The brightness of the top status bar icons can be set by passing statusBarIconBrightness whose type is Brightness enum. It only affects Android version M and greater.
The color of the status bar can be set by passing a Color as the statusBarColor argument. To make the status bar looks transparent, you can set the opacity of the color. The brightness of the top status bar icons can be set by passing statusBarIconBrightness whose type is Brightness enum.
I concluded that in this particular case, setting Brightness.light means "change the status bar icons' color to some color that is suitable for light colored status bar (White or similar color status bar background) which means that the system will set the icons to black in order for the user to be able to see the icons. Hope this helped!
That's because you're not explicitly changing AppBar
's brightness
in your Test
page. Run this code and see the difference:
void main() {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.black.withOpacity(0), //top bar color
// statusBarIconBrightness: Brightness.dark, // don't use this
),
);
runApp(MyApp2());
}
class MyApp2 extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("AppBar"),
brightness: Brightness.light, // use this instead
),
),
);
}
}
Output-1 (Brightness.dark):
Output-2 (Brightness.light):
I was trying something similar, but the status bar was transparent instead of blue. I added the following and it worked:
theme: ThemeData(
appBarTheme: AppBarTheme(
brightness: Brightness.light,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With