Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change the status bar Icon Brightness in flutter app?

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.

like image 203
rahul Kushwaha Avatar asked Dec 04 '19 07:12

rahul Kushwaha


People also ask

How to brighten status bar icons in flutter?

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;

How to change the status bar color and brightness in Android?

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.

How do I change the color of the status bar icons?

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.

What does brightness mean in the status bar?

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!


2 Answers

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):

enter image description here

Output-2 (Brightness.light):

enter image description here

like image 181
CopsOnRoad Avatar answered Sep 28 '22 06:09

CopsOnRoad


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,
like image 21
fermoga Avatar answered Sep 28 '22 06:09

fermoga