78 lines
2.3 KiB
Dart
78 lines
2.3 KiB
Dart
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());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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,
|
|
),
|
|
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,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|