简体   繁体   English

如何更改深色和浅色主题的颤动文本颜色?

[英]How to change flutter text color for dark and light theme?

如何更改深色主题和浅色主题的颤动文本颜色,有人可以回答我吗?

title:  Text('Kitchen Name', )

There are two ways of doing so:有两种方法:

  1. You can set both a theme and a darkTheme variance in your MaterialApp properties and having it automatically changed whenever the OS theme changes, based on the text properties that you set;您可以在MaterialApp属性中设置themedarkTheme变化,并根据您设置的文本属性在操作系统主题更改时自动更改;
  2. Or, you can manually check for the current brightness in your Text style's property (when the brightness is dark, the OS should be using a dark theme, and a light when it's light).或者,您可以手动检查Text样式属性中的当前亮度(当亮度较暗时,操作系统应该使用深色主题,而在浅色时使用浅色)。
title: Text(
          'Kitchen Name',
          style: Theme.of(context).brightness == Brightness.dark ? TextStyle(color: Colors.white) : TextStyle(color: Colors.black),
        ),

I'd pick the 1 since it's the most correct way of doing it.我会选择 1,因为它是最正确的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:如何根据当前主题(暗/亮)更改状态栏和导航栏颜色 - Flutter: How to change StatusBar and NavigationBar color according to current theme(dark/light) 当我们使用深色/浅色主题时,如何更改 flutter 中状态栏的颜色? - how to change the color of status bar in flutter when we are using dark/light theme? 如何在 ontap flutter 上将整个应用程序更改为深色和浅色主题? - How to change entire app to dark and light theme on ontap flutter? 如何在 Flutter 中使用 Provider 切换明暗主题? - How to use a switch to change between light and dark theme with Provider in Flutter? Flutter 主题(深色&浅色) - Flutter Theme (dark & light) 明暗主题 Flutter - Light and dark theme Flutter 如何根据深色/浅色主题设置颜色? - How to set the color based on dark / light theme? Flutter:如何在 Flutter 中使用 Switch 更改主题 - 我已使用 Provider 实现了此明暗主题,但无法使用 switch 更改 - Flutter: How I Can Change Theme Using Switch in Flutter - I have Implemented this Light and Dark Theme Using Provider, But can not change with switch 如何在 Flutter 中通过更改主题来更改文本颜色 - How to change the Text color with change of theme in Flutter 如何根据应用程序主题(深色和浅色)更改 google map 的主题? - How to Change theme of google map according to app theme (Dark & Light)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM