I tried the method SystemChrome.setSystemUIOverlayStyle()
, as far as I tested (Flutter SDK v1.9.1+hotfix.2, running on iOS 12.1) it works perfect for Android. But for iOS, e.g. if your first screen FirstScreen()
doesn’t have an AppBar
, but the second SecondScreen()
does, then at launch the method does set the color in FirstScreen()
. However, after navigating back to FirstScreen()
from SecondScreen()
, the status bar color becomes transparent.
I come up with a hacky workaround by setting an AppBar()
with zero height, then status bar’s color gets changed by the AppBar, but the AppBar itself is not visible. Hope it would be useful to someone.
// FirstScreen that doesn't need an AppBar
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(0),
child: AppBar( // Here we create one to set status bar color
backgroundColor: Colors.black, // Set any color of status bar you want; or it defaults to your theme's primary color
)
)
);
}
// SecondScreen that does have an AppBar
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar()
}
}
Here is the screenshot of FirstScreen
in iPhone Xs Max iOS 12.1: