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:
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
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.
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.
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.
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.
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.
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.
Edit:
appBar: AppBar(
elevation: 0,
brightness: Brightness.light, // this makes status bar text color black
backgroundColor: Colors.white,
)
Output:
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.
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"),
)
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With