更改Flutter(带有动态主题)中黑暗模式的文本颜色? [英] Changing text color for dark mode in Flutter(with Dynamic Theme)?

查看:84
本文介绍了更改Flutter(带有动态主题)中黑暗模式的文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我选择暗模式时,文本变成白色,但我想使所有文本变成白色70或类似的东西(包括按钮和常规文本).如何定义深色模式的默认文本颜色?

Text turn to white when I got select dark mode but I want to make all texts white70 or something(including buttons and regular texts). How can I definde the default text color for dark mode?

我的主题数据现在是这样的:

My Theme data like this right now:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DynamicTheme(
        defaultBrightness: Brightness.light,
        data: (brightness) => ThemeData(
      primarySwatch: Colors.blueGrey,
      brightness: brightness,
        ),

推荐答案

您可以执行类似的操作(随意更改):

You can do something similar to this (Feel free to change things as you'd like):

首先转到ios/Runner文件夹.接下来打开info.plist并将以下几行添加到Dict部分.

At first go to ios/Runner folder. Next open info.plist and add the following lines into the Dict section.

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

下一步.确保您在MaterialApp的主题设置中包含以下行:

Next. Make sure you have these lines in Theme settings of your MaterialApp:

MaterialApp(
    themeMode: ThemeMode.light, // Change it as you want
    theme: ThemeData(
        primaryColor: Colors.white,
        primaryColorBrightness: Brightness.light,
        brightness: Brightness.light,
        primaryColorDark: Colors.black,
        canvasColor: Colors.white,
        // next line is important!
        appBarTheme: AppBarTheme(brightness: Brightness.light)),
    darkTheme: ThemeData(
        primaryColor: Colors.black,
        primaryColorBrightness: Brightness.dark,
        primaryColorLight: Colors.black,
        brightness: Brightness.dark,
        primaryColorDark: Colors.black,      
        indicatorColor: Colors.white,
        canvasColor: Colors.black,
        // next line is important!
        appBarTheme: AppBarTheme(brightness: Brightness.dark)),

这篇关于更改Flutter(带有动态主题)中黑暗模式的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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