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

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

问题描述

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

How to set status bar color when AppBar not present.

我已经尝试过了,但是没有用。

I have tried this but not working.

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';

接下来,只需将其放入应用程序的 build函数

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

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

另外,您可以设置有用的属性,例如: statusBarIconBrightness systemNavigationBarColor systemNavigationBarDividerColor

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

如果您更喜欢使用颤振/小工具来执行相同的操作,请考虑使用 AnnotatedRegion< SystemUiOverlayStyle> 小部件。

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

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

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

有关详细信息,请转到< a href = https://api.flutter.dev/flutter/services/SystemChrome/setSystemUIOverlayStyle.html rel = noreferrer> API文档

For more infos, head over to the API Docs

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

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