How to change status bar color in Flutter?
Asked Answered
H

41

234

I am trying to change the status bar color to white. I found this pub on flutter. I tried to use the example code on my dart files.

Hexagram answered 25/9, 2018 at 1:42 Comment(1)
On iOS, you can simple wrap the body of your scaffold in a safe area. The colour you set as the scaffold's background colour will become the status bar colour.Brash
O
220

Works totally fine in my app

import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.white);
    return MaterialApp(
      title: app_title,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(title: home_title),
    );
  }
}

UPD: Recommended solution (Flutter 2.0 and above)

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.white
));

Note: This package is not compatible with Flutter 3.0 or above [1]: https://pub.dev/packages/flutter_statusbarcolor

Organizer answered 25/9, 2018 at 7:28 Comment(21)
Many thanks Andrey; It works ... the only issue is that the background is white but the clock, wireless and other text and icons are also in white .. I am not sure why!! (I am expecting the text and icons to be in black)Hexagram
I didn't find this too. And I've edited post - there is another and simpler solution for setting status bar colorOrganizer
Where do I put this other solution code? in my main.dart?Hexagram
You can put in inside build methodOrganizer
I get "Target URI doesn't exist" for import package:flutter_statusbarcolor/flutter_statusbarcolor.dart';Hay
The question was about this package - pub.dev/packages/flutter_statusbarcolor You have to add dependency to pubspecOrganizer
Excelent. Just a little comment... You have to open the pubspec.yaml file and add the next line under dependencies line: flutter_statusbarcolor: ^0.2.3 (Check the last version here [pub.dev/packages/flutter_statusbarcolor#-installing-tab-])Lorenz
is SystemChrome solution works on both Android and iOS ??Turoff
@JayTillu no. For iOS you have to use flutter_statusbarcolor or set color for each AppBar manuallyOrganizer
it changes the background of the status bar, not the text of the status bar itself.Swallowtailed
@AbdulrahmanMasoud the question was about statusbar color, not textOrganizer
flutter_statusbarcolor is broken on iOS with landscape orientation (at least on iPad)Butanol
How to change text color of status bar? Any suggestion?Behoof
@TryHarder not found exact solution, I need, want to change Status bar background color green with white text in light theme and black background color with white text in dark theme, still searching perfect solution. Kindly share, whenever you find it, I will do the same with you. Thanks.Behoof
@Behoof seems like you can only change the text or icon to black or white color ( IOS and Android) and the status bar color can be any ( blue, red, .... etc). I use SystemChrome.setSystemUIOverlayStyle for Android and FlutterStatusbarcolor package for IOS. I not sure why but it seems like SystemChrome.setSystemUIOverlayStyle doesn't work when i test on IOS. Hope this helps you, good luck mate :DClichy
@TryHarder I have already added your suggested code with many variants, but still did not get any success. Thanks again.Behoof
Add attribute: statusBarIconBrightness: Brightness.dark in order to avoid status bar icon's color to be changed to white also.Serajevo
@AndreyTurkovsky FlutterStatusbarcolor.setStatusBarColor(Colors.white); returns Future. So I have to call the build method after some delay to see the status bar color and text color. I want statusbar color black and text white.Turoff
@JayTillu there is very short delay, in my experience it was unnoticed by userOrganizer
Not suitable answer, this is common functionality so don't need to use third-party plugin for this, and this plugin has been discontinue now, so avoid unnecessary plugin to do common things !Traipse
better to use pub.dev/packages/flutter_statusbarcolor_nsChaucerian
I
330

Update Flutter 2.0 (Recommended):

On latest Flutter version, you should use:

AppBar(
  systemOverlayStyle: SystemUiOverlayStyle(
    // Status bar color
    statusBarColor: Colors.red, 

    // Status bar brightness (optional)
    statusBarIconBrightness: Brightness.dark, // For Android (dark icons)
    statusBarBrightness: Brightness.light, // For iOS (dark icons)
  ),
)

Only Android (more flexibility):

import 'package:flutter/services.dart';

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    systemNavigationBarColor: Colors.blue, // navigation bar color
    statusBarColor: Colors.pink, // status bar color
  ));
}

Both iOS and Android:

appBar: AppBar(
  backgroundColor: Colors.red, // Status bar color
)

A bit hacky but works on both iOS and Android:

Container(
  color: Colors.red, // Status bar color
  child: SafeArea(
    left: false,
    right: false,
    bottom: false,
    child: Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.blue, // App bar color
      ),
    ),
  ),
) 
Indreetloire answered 28/10, 2018 at 14:25 Comment(17)
I am newbie in flutter and I want to know What if we put these lines in build method of any widget ? Does it make any difference ?Specialty
It will work and does not make any difference. Just keep in mind, the color will be set with params of the latest caller.Pippa
How can I change the status bar text color when changing the app theme from light to dark and vice versa? Are there any properties in ThemeData class?Contemptuous
@VinothVino Sorry but you can't give text color of your choice to status bar items, all you can do is change brightness, where Brightness.light shows black text color and Brightness.dark shows white.Indreetloire
Thanks for the reply bro. How can I change brightness dynamically? I'm changing dark mode, it's not updating properly. If I hot restart the app then it works.Contemptuous
@VinothVino I'm talking about AppBar's brightness property, you can change that dynamically using setState right?Indreetloire
It's working now. Thanks for the help man! @IndreetloireContemptuous
This changes the status bar and the app bar :/Dimer
How can I change the brightness Statusbar if I don't have AppBar?Turoff
@JayTillu You can pass statusBarBrightness property to SystemUiOverlayStyle constructor.Indreetloire
@Indreetloire will it work on both Android and iOS ??Turoff
@JayTillu It should, however, I didn't test it on any of the platform.Indreetloire
Add attribute: statusBarIconBrightness: Brightness.dark in order to avoid status bar icon's color to be changed to white also.Serajevo
I am on Flutter 2.0 and tried your first recommended solution, but it doesn't work. Any help plz?Kieffer
@HassanHammad Please share your code (in a separate question).Indreetloire
@Indreetloire In the last option (which is a good hack) how will I be able to change the status bar icon's color?Turoff
@JayTillu You can't change icon's color with that hack. Use other solutions.Indreetloire
O
220

Works totally fine in my app

import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.white);
    return MaterialApp(
      title: app_title,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(title: home_title),
    );
  }
}

UPD: Recommended solution (Flutter 2.0 and above)

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.white
));

Note: This package is not compatible with Flutter 3.0 or above [1]: https://pub.dev/packages/flutter_statusbarcolor

Organizer answered 25/9, 2018 at 7:28 Comment(21)
Many thanks Andrey; It works ... the only issue is that the background is white but the clock, wireless and other text and icons are also in white .. I am not sure why!! (I am expecting the text and icons to be in black)Hexagram
I didn't find this too. And I've edited post - there is another and simpler solution for setting status bar colorOrganizer
Where do I put this other solution code? in my main.dart?Hexagram
You can put in inside build methodOrganizer
I get "Target URI doesn't exist" for import package:flutter_statusbarcolor/flutter_statusbarcolor.dart';Hay
The question was about this package - pub.dev/packages/flutter_statusbarcolor You have to add dependency to pubspecOrganizer
Excelent. Just a little comment... You have to open the pubspec.yaml file and add the next line under dependencies line: flutter_statusbarcolor: ^0.2.3 (Check the last version here [pub.dev/packages/flutter_statusbarcolor#-installing-tab-])Lorenz
is SystemChrome solution works on both Android and iOS ??Turoff
@JayTillu no. For iOS you have to use flutter_statusbarcolor or set color for each AppBar manuallyOrganizer
it changes the background of the status bar, not the text of the status bar itself.Swallowtailed
@AbdulrahmanMasoud the question was about statusbar color, not textOrganizer
flutter_statusbarcolor is broken on iOS with landscape orientation (at least on iPad)Butanol
How to change text color of status bar? Any suggestion?Behoof
@TryHarder not found exact solution, I need, want to change Status bar background color green with white text in light theme and black background color with white text in dark theme, still searching perfect solution. Kindly share, whenever you find it, I will do the same with you. Thanks.Behoof
@Behoof seems like you can only change the text or icon to black or white color ( IOS and Android) and the status bar color can be any ( blue, red, .... etc). I use SystemChrome.setSystemUIOverlayStyle for Android and FlutterStatusbarcolor package for IOS. I not sure why but it seems like SystemChrome.setSystemUIOverlayStyle doesn't work when i test on IOS. Hope this helps you, good luck mate :DClichy
@TryHarder I have already added your suggested code with many variants, but still did not get any success. Thanks again.Behoof
Add attribute: statusBarIconBrightness: Brightness.dark in order to avoid status bar icon's color to be changed to white also.Serajevo
@AndreyTurkovsky FlutterStatusbarcolor.setStatusBarColor(Colors.white); returns Future. So I have to call the build method after some delay to see the status bar color and text color. I want statusbar color black and text white.Turoff
@JayTillu there is very short delay, in my experience it was unnoticed by userOrganizer
Not suitable answer, this is common functionality so don't need to use third-party plugin for this, and this plugin has been discontinue now, so avoid unnecessary plugin to do common things !Traipse
better to use pub.dev/packages/flutter_statusbarcolor_nsChaucerian
T
134

For those who uses AppBar

If you use AppBar then updating status bar color is as simple as this:

Scaffold(
  appBar: AppBar(
    // Use [Brightness.light] for black status bar 
    // or [Brightness.dark] for white status bar
    // https://mcmap.net/q/117117/-how-to-change-status-bar-color-in-flutter
    brightness: Brightness.light 
  ),
  body: ...
)

To apply for all app bars:

return MaterialApp(
  theme: Theme.of(context).copyWith(
    appBarTheme: Theme.of(context)
        .appBarTheme
        .copyWith(brightness: Brightness.light),
  ...
  ),

For those who don't use AppBar

Wrap your content with AnnotatedRegion and set value to SystemUiOverlayStyle.light or SystemUiOverlayStyle.dark:

return AnnotatedRegion<SystemUiOverlayStyle>(
  // Use [SystemUiOverlayStyle.light] for white status bar 
  // or [SystemUiOverlayStyle.dark] for black status bar
  // https://mcmap.net/q/117117/-how-to-change-status-bar-color-in-flutter
  value: SystemUiOverlayStyle.light,
  child: Scaffold(...),
);
Toxemia answered 27/9, 2019 at 9:45 Comment(6)
This method doesn't allow to set the exact colorTerrify
if you want to get the status bar color according to your theme, you can always use brightness: Theme.of(context).brightnessPeanuts
value: SystemUiOverlayStyle.light (or .dark) does the same thingDarnel
what if we don't want to change the statusbar color and put as default by the system of the device. what should we do in this case?Inoffensive
Just don't do anything thenToxemia
thanks!, using AnnotatedRegion is working.Farina
C
96

Edit for Flutter 2.0.0

The answer below does not work anymore when you have an AppBar on the screen. You now need to configure the AppBarTheme.brightness and AppBarTheme.systemOverlayStyle correctly in that case.

Answer

Instead of the often suggested SystemChrome.setSystemUIOverlayStyle() which is a system wide service and does not reset on a different route, you can use an AnnotatedRegion<SystemUiOverlayStyle> which is a widget and only has effect for the widget that you wrap.

AnnotatedRegion<SystemUiOverlayStyle>(
   value: SystemUiOverlayStyle(
      statusBarColor: Colors.white,
  ),
  child: Scaffold(
      ...
  ),
)
Calendar answered 9/1, 2020 at 21:30 Comment(6)
This is the best answer, as popping back to the screen after a push will reset the status bar. This was first mentioned by Jordy here https://mcmap.net/q/119652/-flutter-how-to-set-status-bar-color-when-appbar-not-presentKneecap
I also believe this is the best answer if we need it throughout the appLabyrinth
I am using it in one screen and it is having effect on all other screens in app. I am using it on my first screen and naturally the other screens are connected so it is having the same status bar color, in this white, on all other screens. How to prevent this behavior? How to make it work on only a particular scaffold?Encase
@Encase i had same issue. what i did was using 1 global color, which is used in most views. But in specific views, where was needed different color, i just reused same widget but with different colorAndalusite
the best answer should be insteadedHatchery
This doesn't work on iOSAlodium
C
32

This worked for me:

Import Service

import 'package:flutter/services.dart';

Then add:

@override
  Widget build(BuildContext context) {

    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.white,
      statusBarBrightness: Brightness.dark,
    ));
    return MaterialApp(home: Scaffold(
Cordwood answered 3/4, 2020 at 16:8 Comment(2)
What if dark theme is active on the device? Can we change status bar color dynamically?Phyfe
This is outdated by nowFootboard
W
30

Change status bar color when you are not using AppBar

First Import this

import 'package:flutter/services.dart';

Now use below code to change status bar color in your application when you are not using the AppBar

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
    statusBarColor: AppColors.statusBarColor, // set Status bar color in Android devices
    statusBarIconBrightness: Brightness.dark, // set Status bar icons color in Android devices
    statusBarBrightness: Brightness.dark, // set Status bar icon color in iOS
  )
); 

To change the status bar color in iOS when you are using SafeArea

Scaffold(
  body: Container(
    color: Colors.red, // Set your status bar color here
    child: SafeArea(child: Container(
      // Add your Widget here
    )),
  ),
); 
Walling answered 4/4, 2020 at 8:46 Comment(2)
I got caught out by putting the SafeArea before the scaffold which stopped the background color from the scaffold from extending behind the status bar.Encompass
I used SafeArea and your solution saved me time. Thank you :)Brahmanism
S
16

I think this will help you:

import 'package:flutter/services.dart';
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
        systemNavigationBarColor: Colors.white, // navigation bar color
        statusBarColor: Colors.white, // status bar color
        statusBarIconBrightness: Brightness.dark, // status bar icons' color
        systemNavigationBarIconBrightness: Brightness.dark, //navigation bar icons' color
    ));
Sidle answered 30/10, 2019 at 21:7 Comment(0)
K
14

What worked for me (For those who don't use AppBar)

Add AppbBar with preferred color and then set : toolbarHeight: 0

 child: Scaffold(
    appBar: AppBar(
      toolbarHeight: 0,
      backgroundColor: Colors.blue,
      brightness: Brightness.light,
    )
Klondike answered 8/3, 2021 at 10:9 Comment(1)
This is te best answer sor far. With the others you get a lot of inconsistencies in iOS, especially when you don't have an AppBar.Revkah
B
9

I can't comment directly in the thread since I don't have the requisite reputation yet, but the author asked the following:

the only issue is that the background is white but the clock, wireless and other text and icons are also in white .. I am not sure why!!

For anyone else who comes to this thread, here's what worked for me. The text color of the status bar is decided by the Brightness constant in flutter/material.dart. To change this, adjust the SystemChrome solution like so to configure the text:

    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.red,
      statusBarBrightness: Brightness.dark,
    ));

Your possible values for Brightness are Brightness.dark and Brightness.light.

Documentation: https://api.flutter.dev/flutter/dart-ui/Brightness-class.html https://api.flutter.dev/flutter/services/SystemUiOverlayStyle-class.html

Blatant answered 21/8, 2019 at 2:44 Comment(0)
M
8

This is everything you need to know:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    systemNavigationBarColor: Colors.amber, // navigation bar color
    statusBarColor: Colors.white, // status bar color
    statusBarIconBrightness: Brightness.dark, // status bar icon color
    systemNavigationBarIconBrightness: Brightness.dark, // color of navigation controls
  ));
  runApp(MyApp());
}
Maddalena answered 10/8, 2020 at 4:24 Comment(0)
S
7

It can be achieved in 2 steps:

  1. Set the status bar color to match to your page background using FlutterStatusbarcolor package
  2. Set the status bar buttons' (battery, wifi etc.) colors using the AppBar.brightness property

If you have an AppBar:

  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.white);
    return Scaffold(
      appBar: AppBar(
        brightness: Brightness.light,
        // Other AppBar properties
      ),
      body: Container()
    );
  }

If you don't want to show the app bar in the page:

  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.white);
    return Scaffold(
      appBar: AppBar(
        brightness: Brightness.light,
        elevation: 0.0,
        toolbarHeight: 0.0, // Hide the AppBar
      ),
      body: Container()
  }
Spindling answered 29/8, 2020 at 17:6 Comment(1)
this is tested for SafeArea in ios also?Magnoliamagnoliaceous
S
7

Using AnnotatedRegion is what works best for me, especially if I don't have an AppBar

import 'package:flutter/services.dart';

...

Widget build(BuildContext context) {
   return Scaffold(
      body: AnnotatedRegion<SystemUiOverlayStyle>(
         value: SystemUiOverlayStyle.light,                
         child: ...,
      ),
   );
}
Silvas answered 16/9, 2021 at 22:44 Comment(1)
Plagiarized from here.Buckboard
I
6

[Tested in Android] This is how I was able to make status bar transparent and it's text color dark,

import 'package:flutter/services.dart';

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.transparent, // transparent status bar
    statusBarIconBrightness: Brightness.dark // dark text for status bar
  ));
  runApp(MyApp());
}
Irreversible answered 29/3, 2021 at 12:42 Comment(0)
B
6

From Flutter 2.5.0

brightness property is deprecated in AppBar

We need to use, systemOverlayStyle property

Example,If you are using an AppBar

AppBar(
      title: Text("Title"),
      systemOverlayStyle: SystemUiOverlayStyle.dark) //for dark color
Bedlam answered 6/10, 2021 at 7:16 Comment(2)
Thank you nothing else worked. This is the only thing that works in Flutter 2.5.0Parada
I'm now using Flutter 2.5.2,this is not work. I found that ``` SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light); ``` is the correct way to make it work on iOSLemniscate
I
5

This one will also work

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
Insulation answered 18/2, 2020 at 12:56 Comment(0)
F
4

on the main.dart file import service like follow

  import 'package:flutter/services.dart';

and inside build method just add this line before return

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.orange
)); 

Like this:

@override
 Widget build(BuildContext context) {
   SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
       statusBarColor: CustomColors.appbarcolor
    ));
    return MaterialApp(
    home: MySplash(),
    theme: ThemeData(
      brightness: Brightness.light,
      primaryColor: CustomColors.appbarcolor,
    ),
  );
 }
Fridge answered 26/6, 2019 at 4:48 Comment(0)
T
4

This is by far is the best way, it requires no extra plugins.

Widget emptyAppBar(){
  return PreferredSize(
      preferredSize: Size.fromHeight(0.0), 
      child: AppBar(
        backgroundColor: Color(0xFFf7f7f7),
        brightness: Brightness.light,
      )
  );
}

and call it in your scaffold like this

return Scaffold(
      appBar: emptyAppBar(),
     .
     .
     .
Trothplight answered 30/7, 2020 at 12:43 Comment(0)
C
4

Works for both iOS and Android

import 'package:flutter/services.dart';

@override
Widget build(BuildContext context) {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);

  return Scaffold();
}
    
Charmine answered 22/9, 2020 at 4:48 Comment(0)
N
4

Most of the answers are using SystemChrome which only works for Android. My solution is to combine both AnnotatedRegion and SafeArea into new Widget so it also works in iOS. And I can use it with or without AppBar.

class ColoredStatusBar extends StatelessWidget {
  const ColoredStatusBar({
    Key key,
    this.color,
    this.child,
    this.brightness = Brightness.dark,
  }) : super(key: key);

  final Color color;
  final Widget child;
  final Brightness brightness;

  @override
  Widget build(BuildContext context) {
    final defaultColor = Colors.blue;
    final androidIconBrightness =
        brightness == Brightness.dark ? Brightness.light : Brightness.dark;
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle(
        statusBarColor: color ?? defaultColor,
        statusBarIconBrightness: androidIconBrightness,
        statusBarBrightness: brightness,
      ),
      child: Container(
        color: color ?? defaultColor,
        child: SafeArea(
          bottom: false,
          child: Container(
            child: child,
          ),
        ),
      ),
    );
  }
}

Usage: Place it to top of page's widget.

@override
Widget build(BuildContext context) {
  return ColoredStatusBar(
    child: /* your child here */,
  );
}
Novena answered 22/12, 2020 at 17:46 Comment(1)
Thanks Man, This works nicely, just hides part of the debug tag, but that's Ok i guess.Celaeno
D
4

None of the answers seem to mention that you can do it with your ThemeData function in your main MaterialApp widget.

return MaterialApp(
  theme: ThemeData(
    appBarTheme: const AppBarTheme(
      systemOverlayStyle: SystemUiOverlayStyle(
        statusBarColor: Colors.white,
      ),
    ),
  ),
),

This can also be done in the darkTheme ThemeData.

Dearborn answered 17/2, 2022 at 18:17 Comment(0)
A
4

The best way with out any packages

Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        toolbarHeight: 0,
        backgroundColor: Colors.transparent,
        elevation: 0,
        systemOverlayStyle: const SystemUiOverlayStyle(
          statusBarColor: Colors.transparent, // <-- SEE HERE
          statusBarIconBrightness:
              Brightness.dark, //<-- For Android SEE HERE (dark icons)
          statusBarBrightness: Brightness.light,
        ),
      ),.......
Aglimmer answered 22/8, 2022 at 10:32 Comment(1)
Does this work for iOS?Alodium
D
4

Latest solution. Flutter 2.0 and above

For those who use AppBar:

/// WORKS on the screen where appBar is used
Scaffold(
      appBar: AppBar(
        systemOverlayStyle: SystemUiOverlayStyle(
          // statusBarColor: Colors.red, // You can use this as well
          statusBarIconBrightness: Brightness.dark, // OR Vice Versa for ThemeMode.dark
          statusBarBrightness: Brightness.light, // OR Vice Versa for ThemeMode.dark
        ),
      ),
     ), 

For those who DON'T use AppBar:

  1. Put the code below on the root screen's build function to AFFECT all the screens below:
void main() {
  runApp(MyApp());
}

// This widget is the root of your application.
class MyApp extends StatelessWidget {

  /// WORKS on every screen EXCEPT the screen in which appBar is used
  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(
      // statusBarColor: Colors.red, // You can use this as well
      statusBarIconBrightness: Brightness.dark, // OR Vice Versa for ThemeMode.dark
      statusBarBrightness: Brightness.light, // OR Vice Versa for ThemeMode.dark
    ),
  );
  @override
  Widget build(BuildContext context) {}
}
  1. Put the code below on the single screen's build function to AFFECT this screen only:
class SingleScreen extends StatelessWidget {

  /// WORKS on a single screen where appBar is NOT used
  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(
      // statusBarColor: Colors.red, // You can use this as well
      statusBarIconBrightness: Brightness.dark, // OR Vice Versa for ThemeMode.dark
      statusBarBrightness: Brightness.light, // OR Vice Versa for ThemeMode.dark
    ),
  );
  @override
  Widget build(BuildContext context) {}
}
Destructor answered 23/9, 2022 at 6:32 Comment(1)
Why is your code in "Put the code below on the single screen's build function to AFFECT this screen only" snippet is outside build function? is it correct?Unpredictable
I
3
 return Scaffold(
      backgroundColor: STATUS_BAR_COLOR_HERE,
      body: SafeArea(
        child: scaffoldBody(),
      ),
);
Inspan answered 5/5, 2020 at 9:23 Comment(0)
V
3

You can do as follows,

SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(
        statusBarColor: Colors.grey.withOpacity(0.5),
        statusBarIconBrightness: Brightness.dark,
        statusBarBrightness:
            Platform.isAndroid ? Brightness.dark : Brightness.light,
        systemNavigationBarColor: Colors.white,
        systemNavigationBarDividerColor: Colors.grey,
        systemNavigationBarIconBrightness: Brightness.dark,
      ),
    );

Add this code to your main.dart build method,

Very answered 28/10, 2021 at 16:41 Comment(0)
F
3

this (inside the scaffold) creates a black statusbar with light content. (no Appbar)

appBar: AppBar(
      toolbarHeight: 0,
      backgroundColor: Colors.black,
      systemOverlayStyle: SystemUiOverlayStyle.light,
    ),
Fleetwood answered 6/4, 2022 at 1:36 Comment(0)
G
2

to Make it Like your App Bar Color

import 'package:flutter/material.dart';

 Widget build(BuildContext context) {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      systemNavigationBarColor: Colors.transparent,
  ));
 }
Geophilous answered 10/9, 2019 at 10:36 Comment(0)
D
2

None of the existing solutions helped me, because I don't use AppBar and I don't want to make statements whenever the user switches the app theme. I needed a reactive way to switch between the light and dark modes and found that AppBar uses a widget called Semantics for setting the status bar color.

Basically, this is how I do it:

return Semantics(
  container: false,  // don't make it a new node in the hierarchy
  child: AnnotatedRegion<SystemUiOverlayStyle>(
    value: SystemUiOverlayStyle.light,  // or .dark
    child: MyApp(),  // your widget goes here
  ),
);
  • Semantics is imported from package:flutter/material.dart.
  • SystemUiOverlayStyle is imported from package:flutter/services.dart.
Darnel answered 11/9, 2020 at 20:30 Comment(1)
facing Same issue as mentioned above but solution won't work in Andorid 10Mendymene
N
2

Use this way to make your status bar completely white with the dark status bar icons, I use it personally! tested on android worked fine!

import 'package:FileSharing/bodypage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
          // This is the theme of your application.
          //
          // Try running your application with "flutter run". You'll see the
          // application has a blue toolbar. Then, without quitting the app, try
          // changing the primarySwatch below to Colors.green and then invoke
          // "hot reload" (press "r" in the console where you ran "flutter run",
          // or simply save your changes to "hot reload" in a Flutter IDE).
          // Notice that the counter didn't reset back to zero; the application
          // is not restarted.
          primarySwatch: Colors.blue,
          appBarTheme: AppBarTheme(
            color: Colors.white,
            elevation: 0,
            brightness: Brightness.light,
            centerTitle: true,
            iconTheme: IconThemeData(
              color: Colors.black,
            ),
            textTheme: TextTheme(),
          )

          // This makes the visual density adapt to the platform that you run
          // the app on. For desktop platforms, the controls will be smaller and
          // closer together (more dense) than on mobile platforms.
          ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.white,
    ));
    return Scaffold(
      appBar: AppBar(
        brightness: Brightness.light,
        actions: [
          Container(
            width: 63,
            padding: EdgeInsets.only(right: 30),
            child: FloatingActionButton(
              onPressed: null,
              backgroundColor: Colors.pink,
              elevation: 8,
              child: Icon(Icons.person_pin),
            ),
          )
        ],
      ),
    );
  }
}
Novara answered 30/3, 2021 at 13:43 Comment(0)
I
1

you can use for Android:

 import 'package:flutter/services.dart';

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    systemNavigationBarColor: Colors.blue, // navigation bar color
    statusBarColor: Colors.pink, // status bar color
  ));
}
Idolatrize answered 4/6, 2021 at 19:6 Comment(1)
This work inside widgets, just put the widget above build method.Tubby
O
1

you can also use this in SliverAppBar, don't forget to use backwardsCompatibility: false it would not work if you skip this property. also see doc

@override
  Widget build(BuildContext context) {    
    return Scaffold(
      appBar: null,
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
              systemOverlayStyle: SystemUiOverlayStyle(
                  statusBarColor: Colors.transparent,
                  statusBarIconBrightness: Brightness.dark),
              backwardsCompatibility: false,
//... remaining code and close braces..
Oliveolivegreen answered 21/7, 2021 at 23:52 Comment(1)
Thanks it works great!Wohlert
H
1

Full example

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      debugShowCheckedModeBanner: false,
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: const SystemUiOverlayStyle(
        systemNavigationBarColor: Colors.red, // navigation bar color
        systemNavigationBarIconBrightness: Brightness.light, //navigation bar icons' color
      ),
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.red,
          title: const Text('data'),
          systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
            statusBarColor: Colors.red,
            statusBarIconBrightness: Brightness.light,
          ),
        ),
      ),
    );
  }
}
Headpiece answered 19/9, 2021 at 14:42 Comment(0)
C
1

For those of you who are having problems with inconsistencies between iOS and Android color, this worked for me:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

return AppBar(
      systemOverlayStyle: (Platform.isIOS)
          ? SystemUiOverlayStyle.light
          : const SystemUiOverlayStyle(
            statusBarColor: pbsBlue,
            statusBarIconBrightness: Brightness.light,
            statusBarBrightness: Brightness.light,
          ),
      backgroundColor: Colors.blue,
      title: Text('Home'),
    );

Note that this is an extract of a reusable widget for AppBar.

Concinnate answered 6/2, 2023 at 17:45 Comment(1)
Why doesn't setting statusBarColor work on iOS?Alodium
I
0
@override
Widget build(BuildContext context) {
  return Theme(
    data: ThemeData(brightness: Brightness.dark),
    child: Scaffold()
    ....
  )
}
Ingrained answered 27/3, 2020 at 17:32 Comment(1)
Please don't post only code as an answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually of higher quality, and are more likely to attract upvotes.Pig
A
0

I had issues with all mentioned answers, except with solution i did myself: Container(width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).padding.top, color: Colors.green) For views, where is no appBar added i just use container with background which exact height matches status bar height. In this scenario each view can have different status color and i don't need to worry and think about some logic, that somehow wrong views has somehow wrong colors.

Andalusite answered 20/7, 2020 at 13:40 Comment(0)
U
0

First of all you are import this line:

import 'package:flutter/services.dart';

Then You can use bellow this some line of code in main.dart file

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor: Colors.amber, // navigation bar color
statusBarColor: Colors.white, // status bar color
statusBarIconBrightness: Brightness.dark, // status bar icon color
systemNavigationBarIconBrightness: Brightness.dark, // color of navigation controls
));

Note: If you follow above this steep. as a result you control all of screen. But if you control individual screen status bar color then you can try this ...

import 'package:flutter/services.dart';

Widget build(BuildContext context) {
 SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.transparent,
  systemNavigationBarColor: Colors.transparent,
));
}
Unset answered 25/2, 2021 at 6:10 Comment(0)
S
0

You can change it without appbar with giving scaffold(backgroundColor: color); and if you wrap your body with safearea, problem probably solved. I mean this solution is not practice but if you are not using appbar, you can achive with this way.

Splash answered 20/5, 2021 at 8:15 Comment(0)
S
0

At Flutter 2.8:

AppBar(
    backgroundColor: YOUR_COLOR_HERE,
    toolbarHeight: 0,
);
Section answered 17/12, 2021 at 15:38 Comment(0)
M
0

In Your App Bar Widget please add this

      systemOverlayStyle: SystemUiOverlayStyle(
        systemNavigationBarColor:
            const Color(0xfffffbff),
      ),
Mcclanahan answered 13/3, 2023 at 11:25 Comment(0)
S
-1

Solution for changing status bar color both on Android and iOS (working) (DEC-2023)

credits to @Mohamed Nor : see answer

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 0, //if you don't want to use AppBar
        backgroundColor: Colors.red,
      ),
      body: SafeArea(
        child: YourWidget()
    )
    )
}
Steinway answered 14/12, 2023 at 12:19 Comment(0)
W
-2

If you want to change the status color for the whole app, you can use the primaryColorDark property like this:

void main() {
  runApp(
    MaterialApp(
      home: HomeWidget(),
      theme: ThemeData(
        primaryColorDark: Colors.white,
      ),
    ),
  );
}
Waisted answered 3/3, 2021 at 8:19 Comment(0)
A
-3

I solved it by change the whole background color like following:

In the main screen:

return Scaffold(
      backgroundColor: Colors.black,
      body: SafeArea(
     ),
);
Alvertaalves answered 20/10, 2020 at 9:46 Comment(1)
The question is about changing status bar color, and while it will be wrapped with safeArea it won't change the colorProcne

© 2022 - 2024 — McMap. All rights reserved.