flutter - 无法在flutter应用程序中更改状态栏图标亮度?

标签 flutter flutter-layout

在 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”。
怎么了?

在 Android 模拟器上运行。
我不想有 appBarTest()小部件。

最佳答案

那是因为您没有明确更改 AppBarbrightness在您的 Test页。运行此代码并查看差异:

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(亮度.暗):

enter image description here

输出 2(亮度.光):

enter image description here

关于flutter - 无法在flutter应用程序中更改状态栏图标亮度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59170915/

相关文章:

flutter - Flutter:在iOS中更改状态栏颜色

webstorm - 无法与适用于 Web 的 Angular 和适用于移动项目的 Flutter 一起运行 Dart 2 - 计划共享代码

flutter - 如何使用Flutter将2个 float 操作按钮固定在某些特定位置?

dart - 我怎样才能让 BottomNavigationBar 粘在键盘 flutter 的顶部

android - 如何在 Flutter 中实现下拉列表?

android - 如何在抖动中显示横向和纵向的不同布局

dart - 向 Flutter 中的计算函数发送多个参数

Flutter 行将一个项目放在开始位置,将另一个项目放在中间

android - flutter :- Inside the PageView Image is not setting to fit the screen on width?

dart - 如何使用 Flutter 中的 Stack 小部件部分覆盖 View