Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Change status bar color in iOS

I want to change status bar color with package:flutter/services.dart package but it doesn't work. I am using Mac and iOS simulator:

  • Mojave 10.14.6
  • iOS 12.2 simulator / Xr
  • Flutter 1.9.1+hotfix.2
  • Tools • Dart 2.5.0
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) {

    SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(
        statusBarColor: Colors.red // <-- doesn't work
      )
    );

    return MaterialApp(
      title: 'Flutter Demo',
      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,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}
... // other stuff

enter image description here

Even if I put it in the main function:

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

void main() {
  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(
      statusBarColor: Colors.red,
    )
  );
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown])
    .then((_) => runApp(MyApp()));
}
... // the rest code here

As a result I get this if I want to change appBar background color to white.

enter image description here

Haven't tested it for android yet. Is this issue related only to iOS simulator or so? How to fix it?

U.P.D.

This issue starts to drive my nuts.

like image 295
mr.boris Avatar asked Oct 07 '19 13:10

mr.boris


People also ask

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

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 you change the taskbar color on Flutter?

To change the Status Bar Color you have to use the SystemChrome function with the setSystemUIOverlayStyle method, after that, it takes SystemUiOverlayStyle() as a parameter, and then you can use the statusBarColor property and specify the color.

How do you change the color on Flutter?

Step 1: Locate the file where you have placed the Text widget. Step 2: Inside the Text widget, add the Style parameter and assign the TextStyle widget. Step 3: Inside the TextStyle widget, add the color parameter and set the color of your choice. For example, color: Colors.

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. Step 3: In your MainActivity, add this code in your onCreate method.


2 Answers

Edit:

appBar: AppBar(
  elevation: 0,
  brightness: Brightness.light, // this makes status bar text color black
  backgroundColor: Colors.white,
)

Output:

enter image description here


statusBarColor can only be changed in Android and not in iOS, and probably Apple can reject your app if you try do so by some workarounds because they don't want you to have different AppBar and status bar color.

AppBar(backgroundColor: Colors.red) // this changes both AppBar and status bar color in iOS

Apple wants you to stick to their designs which is why changing statusBarColor has no effect on iOS.

like image 99
CopsOnRoad Avatar answered Oct 24 '22 10:10

CopsOnRoad


Try this

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
      backwardsCompatibility: false, "if set to false it doesn't use default app bar theme"
      systemOverlayStyle: SystemUiOverlayStyle(statusBarColor:Colors.orange,"It change the color of status bar"
      statusBarIconBrightness:  Brightness.light "It change the color of status bar icons"),
              )
              );
            }
like image 3
naman kashyap Avatar answered Oct 24 '22 11:10

naman kashyap