Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change status bar color in Flutter?

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.

like image 238
Mohamed Hassan Avatar asked Oct 05 '22 23:10

Mohamed Hassan


People also ask

How do I change my status color on Flutter?

Step 1: Locate the MaterialApp widget. Step 2: Inside the MaterialApp, add the theme parameter with ThemeData class assigned. Step 3: Inside the ThemeData add the appBarTheme parameter and then assign the AppBarTheme class. Step 4: Inside the AppBarTheme , specify the systemOverlayStyle parameter and set the color.

How do I change the color of my status bar?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar.

How do you change the app bar color in Flutter?

You can change appbar color in Flutter, by defining the background color. Basically, you provide the styling instructions by using the backgroundColor property and set its color.

How do I change the color of my status bar Flutter on my Iphone?

To change the statusbar color we will use SystemUiOverlayStyle flutter class property. If we don't want to display Appbar widget we can put Appbar widget inside PreferredSize widget and add preferredSize: Size. zero as 0 so that Appbar will not display but we can change the status bar color and icon theme color.


Video Answer


3 Answers

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
      ),
    ),
  ),
) 
like image 277
CopsOnRoad Avatar answered Oct 20 '22 17:10

CopsOnRoad


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),
    );
  }
}

(this package)

UPD: Recommended solution (Flutter 2.0 and above)

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.white
));
like image 196
Andrey Turkovsky Avatar answered Oct 20 '22 17:10

Andrey Turkovsky


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://stackoverflow.com/a/58132007/1321917
    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://stackoverflow.com/a/58132007/1321917
  value: SystemUiOverlayStyle.light,
  child: Scaffold(...),
);
like image 113
Andrey Gordeev Avatar answered Oct 20 '22 16:10

Andrey Gordeev