I want to set status bar color for each screen. E.g. in screen A status bar color is red and in screen B is blue. I tried many solutions. But each one has it's own problem. like:
AnnotatedRegion(
value: SystemUiOverlayStyle(
systemNavigationBarColor: navigationBarColor,
statusBarColor: statusBarColor,
),
child: child,
);
or this before return in build method:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white
));
My final try :
static void pushNamed({
BuildContext context,
String route,
Object arguments,
Color statusBarColor,
Color navigationBarColor = Colors.black,
}) async {
if (statusBarColor != null) {
await FlutterStatusbarcolor.setStatusBarColor(statusBarColor);
}
await Navigator.pushNamed(
context,
route,
arguments: arguments,
);
}
but sometimes fails. and other problem of this solution is when use back button, color not changed.(I write my code for back button in appbar). and even when in hot reload color change to previous. How can I handle this problem?
Update #2
I create a class for my routing.
static void pushNamedAndRemoveUntil({
BuildContext context,
String route,
Object arguments,
Color statusBarColor,
Color popStatucBarColor,
Color popNavigationBarColor,
Color navigationBarColor,
}) async {
changeSystemColor(statusBarColor, navigationBarColor);
Navigator.pushNamedAndRemoveUntil(
context,
route,
(Route<dynamic> route) => false,
arguments: arguments,
).then((res) {
changeSystemColor(popStatucBarColor, popNavigationBarColor);
});
}
and:
void changeSystemColor(Color statusBarColor, Color navigationBarColor) {
if (statusBarColor != null)
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
systemNavigationBarColor: navigationBarColor ?? Colors.black,
statusBarColor: statusBarColor,
),
);
}
and for using this
Routing.pushNamedAndRemoveUntil(
context: context,
route: Routes.homeScreen,
arguments: user,
statusBarColor: Colors.teal,
);
and now not work when use pushNamedAndRemoveUntil.