dart - Flutter - 如何在 AppBar 不存在时设置状态栏颜色

标签 dart flutter statusbar

当 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();
             }
           },
        ),
       ),
    );
}

输出如下所示:

enter image description here

最佳答案

首先,导入 services包装:

import 'package:flutter/services.dart';

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

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

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


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

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


欲了解更多信息,请访问 API Docs

关于dart - Flutter - 如何在 AppBar 不存在时设置状态栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50501799/

相关文章:

xcode - 互联网上没有适用于模块 'google_maps_flutter' 未找到的解决方案

flutter - 发送回数据后 ListView 不会更新(抖动)

ios - 将状态栏颜色设置为与导航栏相同

dart - 在不删除 src 属性的情况下注入(inject)图像

dart - 当我只设置一次时,我的变量会自动更新。为什么会这样?

dart - Dart 中未处理的异常

dart - FlutterLogo 可以拉伸(stretch)填充吗?

android-studio - ios/mac - Android Studio : Flutter SDK path doesnt set

ios - 状态栏颜色 iOS

swift - 当用户在 webview 中播放视频时,UINavigationController 的导航栏与状态栏重叠