首页 > 解决方案 > Flutter - 如何在 AppBar 不存在时设置状态栏颜色

问题描述

AppBar 不存在时如何设置状态栏颜色。

我已经尝试过了,但没有工作。

Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
    return new Scaffold(
        body: new Container(
        color: UniQueryColors.colorBackground,
        child: new ListView.builder(
           itemCount: 7,
           itemBuilder: (BuildContext context, int index){
             if (index == 0){
               return addTopInfoSection();
             }
           },
        ),
       ),
    );
}

输出如下所示:

在此处输入图像描述

标签: dartflutterstatusbar

解决方案


一、导入services包:

import 'package:flutter/services.dart';

接下来,只需将其放入您的 App的构建函数中:

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.blue, //or set color with: Color(0xFF0000FF)
));

此外,您可以设置有用的属性,例如:statusBarIconBrightnesssystemNavigationBarColorsystemNavigationBarDividerColor


如果您更喜欢使用更加颤动/小部件的方式来做同样的事情,请考虑使用AnnotatedRegion<SystemUiOverlayStyle>小部件。

value:属性可以设置为SystemUiOverlayStyle()包含与上图相同的属性的对象。


有关更多信息,请访问API 文档


推荐阅读