首页 > 解决方案 > Flutter 使用 themeData Brightness 设置苹果状态栏颜色

问题描述

我是新手,想将我的苹果状态栏设置为深色主题(文本为白色)。在我的主文件中,我导入了一个带有主题的单独文件。这就是我现在在 theme.dart 中得到的:

AppThemeData _theme = AppThemeData(
    theme: ThemeData(
      brightness: Brightness.dark, //This gives the error "Unhandled Exception: Bad state: No element"
      cardTheme: CardTheme(
        elevation: 1,
      ),
      primarySwatch: Colors.green,
      backgroundColor: Colors.grey[400],
      visualDensity: VisualDensity.adaptivePlatformDensity,
    ),
    mainScreenBackgroundGradientColors: [Colors.green[700], Colors.green[300]],
    chartThemeData: ChartThemeData(
      lineColor: Colors.yellow[600],
      lineAreaColor: Colors.yellow[100],
      loadingColor: Colors.yellow,
    ),
    deviceChipColor: Colors.green[300],
    infoIconColor: Colors.grey[600]);

我遇到了这个评论 并尝试过,但这没有用,因为上下文不存在。

感谢所有帮助。

标签: iosflutter

解决方案


这最终对我有用:

ThemeData(
      appBarTheme: AppBarTheme(brightness: Brightness.dark),
    ),

推荐阅读