【问题标题】:Flutter: turn off dark mode themeFlutter:关闭深色模式主题
【发布时间】:2020-08-17 08:18:54
【问题描述】:

当我在手机上激活暗模式测试我的应用程序时,cupertinoTabBar 更改为暗主题。我怎样才能防止这种情况?我只希望我的应用以浅色模式为主题。

【问题讨论】:

  • 你能分享你的应用主题代码吗?
  • 您是否尝试将材质应用程序主题设置为浅色?像这样theme: ThemeData.light(),

标签: flutter


【解决方案1】:

在您的顶级应用组件(如 MaterialApp)上将 ThemeMode.light 设置为 themeMode 字段。

例如。

MaterialApp(
   themeMode: ThemeMode.light,
)

另外,Flutter 中还有 3 种模式。

//Use either the light or dark theme based on what
//the user has selected in the system settings.
ThemeMode.system

// Always use the light mode regardless of system preference.
ThemeMode.light

//Always use the dark mode (if available) regardless of system preference.
ThemeMode.dark

【讨论】:

    【解决方案2】:

    这里还有一个很棒的帖子:https://github.com/flutter/flutter/issues/41067#issuecomment-571689955

    我无法更改顶部栏的颜色。解决方法是添加

    <key>UIUserInterfaceStyle</key>
    <string>Light</string>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <true/>
    

    并将其添加到您的 dart 代码中:

    import 'package:flutter/services.dart';
    /// ...
    SystemChrome.setSystemUIOverlayStyle(
          SystemUiOverlayStyle(statusBarBrightness: Brightness.light) // Or Brightness.dark
    );
    

    这将强制您的状态栏变为黑色而不是白色。

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多