在 Flutter 中更改暗模式的文本颜色(使用动态主题)?
Changing text color for dark mode in Flutter(with Dynamic Theme)?
当我进入 select 深色模式时,文本变成白色,但我想将所有文本设为白色 70 或其他内容(包括按钮和常规文本)。如何定义暗模式的默认文本颜色?
我的主题数据现在是这样的:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DynamicTheme(
defaultBrightness: Brightness.light,
data: (brightness) => ThemeData(
primarySwatch: Colors.blueGrey,
brightness: brightness,
),
你可以做类似的事情(随意改变你喜欢的东西):
首先转到 ios/Runner 文件夹。接下来打开 info.plist 并将以下行添加到 Dict 部分。
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
接下来。确保在 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)),
当我进入 select 深色模式时,文本变成白色,但我想将所有文本设为白色 70 或其他内容(包括按钮和常规文本)。如何定义暗模式的默认文本颜色?
我的主题数据现在是这样的:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DynamicTheme(
defaultBrightness: Brightness.light,
data: (brightness) => ThemeData(
primarySwatch: Colors.blueGrey,
brightness: brightness,
),
你可以做类似的事情(随意改变你喜欢的东西):
首先转到 ios/Runner 文件夹。接下来打开 info.plist 并将以下行添加到 Dict 部分。
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
接下来。确保在 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)),