Flutter - AppBar 不存在时如何设置状态栏颜色 [英] Flutter - How to set status bar color when AppBar not present

查看:100
本文介绍了Flutter - AppBar 不存在时如何设置状态栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to set status bar color when AppBar not present.

我试过了,但没有用.

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

输出如下:

推荐答案

首先导入services包:

import 'package:flutter/services.dart';

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

Next, simply put this in the build function of your App:

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

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

Additionally, you can set useful properties like: statusBarIconBrightness, systemNavigationBarColor or systemNavigationBarDividerColor

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

If you prefer a more flutter/widget way of doing the same thing, consider using the AnnotatedRegion<SystemUiOverlayStyle> widget.

value: 属性可以设置为一个 SystemUiOverlayStyle() 对象,其中包含与上述相同的属性.

The value: property can be set to a SystemUiOverlayStyle() object containing the same properties as shown above.

有关更多信息,请转到 API 文档

这篇关于Flutter - AppBar 不存在时如何设置状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆