52 lines
1.7 KiB
Dart
52 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'l10n/app_localizations.dart';
|
|
import 'router.dart';
|
|
import 'theme.dart';
|
|
import 'providers/settings_provider.dart';
|
|
|
|
class ZhinianApp extends ConsumerWidget {
|
|
const ZhinianApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final router = ref.watch(routerProvider);
|
|
final settings = ref.watch(settingsProvider);
|
|
|
|
final platformBrightness = MediaQuery.platformBrightnessOf(context);
|
|
final isDark = switch (settings.themeMode) {
|
|
AppThemeMode.light => false,
|
|
AppThemeMode.dark => true,
|
|
AppThemeMode.system => platformBrightness == Brightness.dark,
|
|
};
|
|
AppColors.applyMode(isDark);
|
|
|
|
return MaterialApp.router(
|
|
title: '智念商家端',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: AppTheme.theme,
|
|
routerConfig: router,
|
|
locale: settings.locale,
|
|
// Pages read AppColors.* statics directly; without a key, Router won't
|
|
// rebuild descendants on a pure theme toggle. Keying by mode forces the
|
|
// whole subtree to remount so every page picks up the new colors.
|
|
builder: (context, child) => KeyedSubtree(
|
|
key: ValueKey<bool>(isDark),
|
|
child: child ?? const SizedBox.shrink(),
|
|
),
|
|
localizationsDelegates: const [
|
|
AppLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
supportedLocales: const [
|
|
Locale('zh', 'CN'),
|
|
Locale('en', 'US'),
|
|
Locale('th', 'TH'),
|
|
],
|
|
);
|
|
}
|
|
}
|