Skip to content

暗色模式

设置MaterialApp

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: // 主页
    ),
  );
}

在桌面平台上切换window_manager按钮暗色模

dart
// 其他按钮同理
return WindowCaptionButton.minimize(
  onPressed: minWindow,
  brightness: Theme.of(context).brightness,
),

Released under the MIT License.