Reputation: 351
I changed in my "setSystemUIOverlayStyle" the color of the status bar at the bottom. This is by default white. I want it in black. This works but I see an error and I don't know where it came from?
Why when I click on my application, at launch, the bar becomes white again for a short time? How to avoid this?
This is the result : I run the app and it launches an initialization page with a loader. Before arriving on the loader, the status bar appears white
Main.dart:
void main() {
runZonedGuarded(() {
setupLocatorService();
runApp(AppScreen());
}, (dynamic error, dynamic stack) {
//print(error);
//print(stack);
});
}
My appScreen:
class AppScreen extends StatelessWidget {
const AppScreen({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
// Status bar color
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.black,
systemNavigationBarColor: Colors.black
));
return ChangeNotifierProvider<Notifier>(
create: (_) => Notifier(),
child: MaterialApp(
title: AppConfig.APPLICATION_NAME,
debugShowCheckedModeBanner: false,
theme: AppTheme().data,
initialRoute: AppRoutes.HOME,
onGenerateRoute: RoutesClass.generate,
),
);
}
}
EDIT : I edit the main, but it's the same result:
void main() {
// Je bloque mon application en verticale
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
// Colors de la status bar
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.black,
systemNavigationBarColor: Colors.black
));
runZonedGuarded(() {
setupLocatorService();
runApp(AppScreen());
}, (dynamic error, dynamic stack) {
//print(error);
//print(stack);
});
}
Upvotes: 0
Views: 3112
Reputation: 7100
I also noticed some strange things when I used SystemChrome.setSystemUIOverlayStyle
. And I decided to use AnnotatedRegion<SystemUiOverlayStyle>
widget to set style of status bar.
Upvotes: 1
Reputation: 105
Don't put SystemChrome
methods in build. Put it in main()
before calling runApp()
void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white,
systemNavigationBarColor: Colors.white
));
runApp(...)
Upvotes: 2