暗色模式
设置MaterialApp
使用google_fonts
dart
@override
Widget build(BuildContext context) {
final brightness = MediaQuery.of(context).platformBrightness;
return MaterialApp(
theme: brightness==Brightness.dark ? ThemeData.dark().copyWith(
textTheme: GoogleFonts.notoSansScTextTheme().apply(
bodyColor: Colors.white,
displayColor: Colors.white,
),
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.lime, // 主题色
brightness: Brightness.dark,
),
) : ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.lime), // 主题色
textTheme: GoogleFonts.notoSansScTextTheme(),
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: // 主页
),
);
}使用外部字体
dart
@override
Widget build(BuildContext context) {
final brightness = MediaQuery.of(context).platformBrightness;
return MaterialApp(
theme: ThemeData(
brightness: brightness,
// brightness: themeGet.darkMode.value ? Brightness.dark : Brightness.light, // 外部控制?
fontFamily: 'Noto',
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.green,
brightness: brightness,
// brightness: themeGet.darkMode.value ? Brightness.dark : Brightness.light, // 外部控制?
),
textTheme: brightness==Brightness.dark ? ThemeData.dark().textTheme.apply(
// textTheme: themeGet.darkMode.value ? ThemeData.dark().textTheme.apply( // 外部控制?
fontFamily: 'Noto',
bodyColor: Colors.white,
displayColor: Colors.white,
) : ThemeData.light().textTheme.apply(
fontFamily: 'Noto',
),
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: // 主页
),
);
}在桌面平台上切换window_manager按钮暗色模
dart
// 其他按钮同理
return WindowCaptionButton.minimize(
onPressed: minWindow,
brightness: Theme.of(context).brightness,
),