如何在Flutter中使Android状态栏亮起

时间:2018-03-08 17:35:40

标签: android dart flutter

正如标题所示,这是关于Flutter。

有没有办法将Android状态栏切换到灯光模式,以便状态栏中的图标显示为黑暗?例如,见图片。

我尝试了可能的解决方案,但没有一个能够解决问题 -

// main.dart
appBar: new AppBar(
      brightness: Brightness.light,
      backgroundColor: Colors.white,
    ),

// MainActivity.kt
// Following 2 lines do change the color of status and nav bars
window.statusBarColor = 0x00000000
window.navigationBarColor = 0x00000000

// This seems to have no effect. Icons are still white.
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

enter image description here

更新

对此的支持正在进行中 - https://github.com/flutter/flutter/issues/17231

2 个答案:

答案 0 :(得分:12)

Flutter团队现在已经添加了对明/暗状态栏控制的支持。要添加,请导入:

import 'package:flutter/services.dart';

然后在App的构建函数中添加它:

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
  statusBarIconBrightness: Brightness.dark
));

答案 1 :(得分:1)

仅需补充说明:

要将状态栏图标更改为深色,请输入以下代码

StatusBarIconBrightness: Brightness.light

并在应用栏中添加亮度。

appBar: AppBar(  
brightness: Brightness.light, )

如果您想在状态栏上使用白色bg,请更改为.light,以使图标变暗,而将.dark更改为带有白色图标的较暗状态栏