新增夜间模式相关代码
This commit is contained in:
+55
-45
@@ -1,11 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'pages/battery_health_page.dart';
|
||||
import 'services/saf_storage_service.dart';
|
||||
import 'theme/app_colors.dart';
|
||||
import 'theme/theme_service.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await SafStorageService().init();
|
||||
await ThemeService.init(); // 🆕
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
@@ -15,53 +18,60 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: '电池健康度',
|
||||
theme: ThemeData(
|
||||
// 🟢 中文用 HarmonyOS Sans SC
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
// 🟢 数字回退到 FlymeFont
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
// 🟢 统一文字颜色为黑色
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: const Color(0xFFFFFFFF),
|
||||
).copyWith(onSurface: Colors.black),
|
||||
textTheme: const TextTheme(
|
||||
// 大标题/数字(健康度、容量等)
|
||||
displayMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: ['Flyme'],
|
||||
color: Colors.black,
|
||||
),
|
||||
// 标题(如“容量百分比变动趋势”)
|
||||
headlineMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: ['Flyme'],
|
||||
color: Colors.black,
|
||||
),
|
||||
// 正文(电压、温度、循环次数等)
|
||||
bodyMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: ['Flyme'],
|
||||
color: Colors.black,
|
||||
),
|
||||
// 小字(日期、辅助信息)
|
||||
bodySmall: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: ['Flyme'],
|
||||
color: Colors.black87,
|
||||
),
|
||||
// 数字专用(大号数字,如健康度百分比)
|
||||
displayLarge: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: ['Flyme'],
|
||||
color: Colors.black,
|
||||
),
|
||||
return ValueListenableBuilder<ThemeMode>(
|
||||
valueListenable: ThemeService.notifier,
|
||||
builder: (context, mode, _) {
|
||||
return MaterialApp(
|
||||
title: '电池健康度',
|
||||
themeMode: mode,
|
||||
theme: _buildTheme(Brightness.light, kLightColors),
|
||||
darkTheme: _buildTheme(Brightness.dark, kDarkColors),
|
||||
home: const BatteryHealthPage(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ThemeData _buildTheme(Brightness brightness, AppColors colors) {
|
||||
return ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: brightness,
|
||||
scaffoldBackgroundColor: colors.background,
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: colors.background,
|
||||
brightness: brightness,
|
||||
),
|
||||
extensions: [colors], // 🆕 注册 ThemeExtension
|
||||
textTheme: TextTheme(
|
||||
displayMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
useMaterial3: true,
|
||||
headlineMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
bodyMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
bodySmall: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textSecondary,
|
||||
),
|
||||
displayLarge: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
),
|
||||
home: const BatteryHealthPage(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user