问题
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,
),
回答1:
You can do something similar to this (Feel free to change things as you'd like):
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/>
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)),
来源:https://stackoverflow.com/questions/60725659/changing-text-color-for-dark-mode-in-flutterwith-dynamic-theme