在Flutter中更改深色模式下文本颜色(使用动态主题)?

3

当我选择深色模式时,文本变成了白色,但我想将所有文本(包括按钮和常规文本)设为白色70或其他颜色。我该如何定义深色模式下的默认文本颜色?

我的主题数据目前是这样的:

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

4
您可以执行类似于以下内容的操作(随意更改内容):
首先进入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)),

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接