How to change Status Bar and App Bar color in Flutter?

后端 未结 6 2044
后悔当初
后悔当初 2020-12-14 17:16

I\'m trying to change the color of system status bar to black. The configuration seems to be overridden by the AppBar class. I can achieve what I want by assigning theme: to

6条回答
  •  隐瞒了意图╮
    2020-12-14 17:32

    If you don't want AppBar at all, then you can just call setSystemUIOverlayStyle in the main function:

    void main() async {
      SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
    
      runApp(new MaterialApp(
        home: new Scaffold(),
      ));
    }
    

    It's more tricky if you have an app bar in one scaffold, and none in another. In that case I had to call setSystemUIOverlayStyle after pushing new route with a scaffold that does not have an appbar:

    @override
    Widget build(BuildContext context) {
      final page = ModalRoute.of(context);
      page.didPush().then((x) {
        SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
      });
    
      return new Scaffold();
    }
    

提交回复
热议问题