2

I have a page that I want to have different style, I've tried to change status bar color from example through SystemChrome like this:

class PageState extends State<Page> {
 @override
 void initState() {
 SystemChrome.setSystemUIOverlayStyle(
     SystemUiOverlayStyle(statusBarColor: Colors.white));
 super.initState();
 }
}

And also set up appBar theme:

appBar: AppBar(
    brightness: Brightness.light,
    backgroundColor: Colors.white,
)

But status bar still uses default color from home page.
Also worth mentioning that if I try to change color with this method on home page it works just fine.

HPressure
  • 187
  • 3
  • 13

1 Answers1

2

To set status bar color you should write code in 'build' method, as below example -

   @override
      Widget build(BuildContext context) {
        SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
            statusBarColor: Color.fromRGBO(41, 167, 77, 50),
            //or set color with: Color(0xFF0000FF)
            statusBarIconBrightness: Brightness.dark));
    return Scaffold();
    }
Nikhat Shaikh
  • 3,175
  • 1
  • 16
  • 21
  • Thank you, my bad – HPressure May 17 '19 at 20:30
  • It's not a good idea to put code like this in `build`, because it will execute every time your widget needs building (possibly hundreds or thousands of times!) Better to put it somewhere which will execute once, eg in `initstate` – James Allen Jun 14 '23 at 15:54