1

I was working with FLUTTER and the Design refers to black color for the status bar and the icon's color of the status bar must be white so how can I change statusbar icon's color in flutter?

Peter Haddad
  • 73,993
  • 25
  • 133
  • 124
Mohammed Sy
  • 231
  • 1
  • 4
  • 12

4 Answers4

3

Add the Snippet below to your main.dart. setSystemUIOverlayStyle allows one to change System overlay styles if any. This will do the job globally in your app.

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark));

This will give you the effect below(iOS & Android). Play around with the properties in SystemUiOverlayStyle to get what you want.

enter image description here

Johngorithm
  • 319
  • 2
  • 8
2

To change the icon to white try the following inside the build method:

import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';

class MyApp extends StatelessWidget {
 @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.white);
    FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
...
}

The method setStatusBarWhiteForeground will change the color of the text and icon to white if it is set to true otherwise the color will be black.

more information here: https://github.com/mchome/flutter_statusbarcolor/blob/master/lib/flutter_statusbarcolor.dart#L29

Peter Haddad
  • 73,993
  • 25
  • 133
  • 124
1

Update:

Use AppBar.systemOverlayStyle:

AppBar(
  systemOverlayStyle: SystemUiOverlayStyle(
    statusBarBrightness: Brightness.dark, // For iOS: (light icons)
    statusBarIconBrightness: Brightness.dark, // For Android: (dark icons)
    statusBarColor: ...,
  ),
)
CopsOnRoad
  • 175,842
  • 51
  • 533
  • 380
  • Thanks for pointing out that there are two options. I was trying to do that for almost half an hour with no success. It happens that I was setting iOS and testing on an android device. T_T – Caio Sant'Anna Apr 18 '22 at 00:51
0

Add this snippet in lib/main.dart file.

        class App extends StatelessWidget {
          // This widget is the root of your application.
          @override
          Widget build(BuildContext context) {
        
            // This code changes background color and icon color of status bar
            SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
              // statusBarColor is used to set Status bar color in Android devices.
              statusBarColor: Colors.transparent,
        
              // To make Status bar icons color white in Android devices.
              statusBarIconBrightness: Brightness.light,
        
              // statusBarBrightness is used to set Status bar icon color in iOS.
              statusBarBrightness: Brightness.dark,
              // Here light means dark icon color for Status bar.
            ));
        
            // material app widget
            return MaterialApp(
        
              // Status bar color
              theme: ThemeData(
                appBarTheme: AppBarTheme(
                  // Brightness.dark will show white color icon
                  brightness: Brightness.dark,
                ),
              ),
        
              color: Colors.white,
        
              title: 'App',
        
              home: Scaffold(),
            );
          }
        }
        

This link will be helpful to you too.

  • Please provide a detailed explanation to your answer, in order for the next user to understand your answer better. – Elydasian Jul 28 '21 at 12:29