我正在向我的 flutter 应用程序添加一个 AboutDialog。
应用程序的主要颜色是黑色,所以我将
AboutDialog
的背景颜色更改为ThemeData
内部的黑色,感谢DialogTheme
,但问题是我不知道如何更改标签的颜色, AboutDialog
:applicationName
、applicationVersion
和applicationLegalese
,这些标签是灰色的,在黑色背景下很难阅读。
我尝试修改
colorScheme
中的 ThemeData
但没有任何效果。
如何将标签的颜色更改为白色?
TextButton(
onPressed: () => showDialog<String>(
barrierColor: Colors.black,
context: context,
builder: (BuildContext context) => AboutDialog(
applicationName: '1234',
applicationIcon: Flexible(
child: Image.asset('assets/icon/icon.png',width: 100,height: 100,),),
applicationVersion:'1234',
applicationLegalese:'1234',
)),
child: const Text( textAlign: TextAlign.center,maxLines: 2,
overflow: TextOverflow.ellipsis,'More Info',
style: TextStyle(color: Colors.white),
)),
void _showAboutDialog(BuildContext context) {
showAboutDialog(
context: context,
applicationName: 'My App',
applicationVersion: '1.0.0',
applicationLegalese: '© 2024 My Company',
children: <Widget>[
Theme(
data: ThemeData(
dialogBackgroundColor: Colors.black,
textTheme: TextTheme(
bodyLarge: TextStyle(color: Colors.white),
bodyMedium: TextStyle(color: Colors.white),
),
),
child: Container(), // This container is required to apply the theme.
),
],
);
}
感谢@Hamed 的启发,这对我有用:
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: '1234',
theme: ThemeData(
textTheme: const TextTheme(
headlineSmall: TextStyle(color: Colors.white),
bodyMedium: TextStyle(color: Colors.white),
bodySmall: TextStyle(color: Colors.white),
), //ADDED THIS
dialogTheme: const DialogTheme(
shadowColor: Colors.white, backgroundColor: Colors.black), //ADDED THIS
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.white,
primary: Colors.white,
secondary: Colors.white),
useMaterial3: true,
),
home: const MyHomePage(title: '1234'),
);
}
}
如果我在
theme
中添加
AboutDialog
则不起作用
编辑: 该设置给我带来了许可证上的一些视觉问题,所以这是最终的代码:
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: '1234',
theme: ThemeData(
scaffoldBackgroundColor: Colors.black, //ADDED THIS
textTheme: const TextTheme(
headlineSmall: TextStyle(color: Colors.white),
headlineMedium: TextStyle(color: Colors.white), //ADDED THIS
headlineLarge: TextStyle(color: Colors.white), //ADDED THIS
bodyMedium: TextStyle(color: Colors.white),
bodySmall: TextStyle(color: Colors.white),
bodyLarge: TextStyle(color: Colors.white), //ADDED THIS
),
dialogTheme: const DialogTheme(
shadowColor: Colors.white, backgroundColor: Colors.black),
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.white,
primary: Colors.white,
secondary: Colors.white
surface: Colors.black, //ADDED THIS
surfaceTint: Colors.white, //ADDED THIS
onSurface: Colors.white, //ADDED THIS
onSurfaceVariant: Colors.white, //ADDED THIS
shadow: Colors.white, //ADDED THIS
),
useMaterial3: true,
),
home: const MyHomePage(title: '1234'),
);
}
}
现在
AboutDialog
和许可证看起来都非常好