Flutter - How to set status bar color when AppBar not present

后端 未结 17 817
孤城傲影
孤城傲影 2020-12-07 23:56

How to set status bar color when AppBar not present.

I have tried this but not working.

Widget build(BuildContext context) {
    SystemChrome.setSys         


        
17条回答
  •  误落风尘
    2020-12-08 00:50

    If you take a look at the source code of AppBar, you can see they use an AnnotatedRegion widget. AnnotedRegion widget gives you more control on System overlay style. This is a more fluttery way to configure the system styles when an app bar is not used.

    From my understanding, this widget automatically sets the statusbar/navigationbar color when the widget wrapped in it gets overlaid by the statusbar/navigationbar.

    You can wrap your widget like this:

    import 'package:flutter/services.dart';
    
    ...    
    
    Widget build(BuildContext context) {
       return Scaffold(
          body: AnnotatedRegion(
             value: SystemUiOverlayStyle.light,                
             child: ...,
          ),
       );
    }
    

    For more information about AnnotatedRegion widget head over to the API Docs

提交回复
热议问题