无法在Flutter应用中更改状态栏图标亮度? [英] Can't change the status bar Icon Brightness in flutter app?

查看:51
本文介绍了无法在Flutter应用中更改状态栏图标亮度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在main.dart中

In main.dart

void main() {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
  statusBarColor: Colors.black.withOpacity(0), //top bar color
  statusBarIconBrightness: Brightness.dark, //top bar icons
  systemNavigationBarColor: Colors.black, //bottom bar color
  systemNavigationBarIconBrightness: Brightness.light, //bottom bar icons
),
);
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
 Widget build(BuildContext context) {
return MaterialApp(
  theme: ThemeData(
    //primaryColor: Color.fromRGBO(113, 201, 206, 1),
    fontFamily: 'Montserrat',
    textTheme: TextTheme(
      headline: TextStyle(
        fontSize: 40,
        fontWeight: FontWeight.w500,
      ),
      title: TextStyle(
        fontWeight: FontWeight.w700,
        fontSize: 16,
      ),
      body1: TextStyle(
        fontSize: 12,
      ),
    ),
  ),
  home: Test(),
  routes: {
    MainScreen.routeName: (context) => MainScreen(),
  },
);
}
}

我正在使用上面的代码更改状态栏的颜色, statusBarIconBrightness:Brightness.dark 无效.它变黑,但几秒钟后又切换回"Brightness.light".怎么了?

I am using the above code to change the color of the status bar, statusBarIconBrightness: Brightness.dark has no effect. It becomes black but after a few seconds it switches back to `Brightness.light'. What's wrong?

在Android模拟器上运行.我不想在 Test()小部件中加入 appBar .

Running on Android Emulator. I don't want to have appBar int the Test() widget.

推荐答案

这是因为您没有在 Test <中显式更改 AppBar 亮度/code>页面.运行以下代码,看看有什么区别:

That's because you're not explicitly changing AppBar's brightness in your Test page. Run this code and see the difference:

void main() {
  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(
      statusBarColor: Colors.black.withOpacity(0), //top bar color
       // statusBarIconBrightness: Brightness.dark, // don't use this
    ),
  );
  runApp(MyApp2());
}

class MyApp2 extends StatelessWidget {
// This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("AppBar"),
          brightness: Brightness.light, // use this instead
        ),
      ),
    );
  }
}

输出1(亮度​​.暗):

输出2(亮度):

这篇关于无法在Flutter应用中更改状态栏图标亮度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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