main.dart 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:go_router/go_router.dart';
  4. import 'package:maxkey_flutter/app_color_scheme.dart';
  5. import 'package:maxkey_flutter/maxkey/maxkey.dart';
  6. import 'package:maxkey_flutter/maxkey/services/users.service.dart';
  7. import 'package:maxkey_flutter/pages/home_page/page.dart';
  8. import 'package:maxkey_flutter/pages/login_page/page.dart';
  9. import 'package:maxkey_flutter/pages/scan_page.dart';
  10. import 'package:maxkey_flutter/pages/settings_page/page.dart';
  11. import 'package:maxkey_flutter/pages/user_page/page.dart';
  12. import 'package:maxkey_flutter/persistent.dart';
  13. import 'package:maxkey_flutter/utils.dart';
  14. import 'package:flutter_localizations/flutter_localizations.dart';
  15. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  16. void main() async {
  17. WidgetsFlutterBinding.ensureInitialized();
  18. await MaxKeyPersistent.init();
  19. runApp(const AppEntry());
  20. }
  21. class AppEntry extends StatelessWidget {
  22. const AppEntry({super.key});
  23. @override
  24. Widget build(BuildContext context) {
  25. return ValueListenableBuilder(
  26. valueListenable: MaxKeyPersistent.instance.themeModeListenable,
  27. builder: (context, value, _) {
  28. return MaterialApp.router(
  29. scaffoldMessengerKey: SCAFFOLD_MESSENGER_KEY,
  30. themeMode: value,
  31. theme: ThemeData.from(colorScheme: AppColorScheme.lightScheme()),
  32. darkTheme: ThemeData.from(colorScheme: AppColorScheme.darkScheme()),
  33. localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
  34. AppLocalizations.delegate,
  35. GlobalCupertinoLocalizations.delegate,
  36. GlobalMaterialLocalizations.delegate,
  37. GlobalWidgetsLocalizations.delegate,
  38. ],
  39. supportedLocales: AppLocalizations.supportedLocales,
  40. routerConfig: _routerConfig,
  41. );
  42. });
  43. }
  44. }
  45. GoRouter _routerConfig = GoRouter(
  46. navigatorKey: NAVIGATOR_KEY,
  47. initialLocation: !MaxKey.instance.authnService.localAuth()
  48. ? RoutePath.loginPage
  49. : RoutePath.homePage,
  50. routes: [
  51. GoRoute(
  52. path: RoutePath.loginPage,
  53. pageBuilder: (context, state) => const CupertinoPage(child: LoginPage()),
  54. ),
  55. GoRoute(
  56. path: RoutePath.homePage,
  57. pageBuilder: (context, state) => const CupertinoPage(child: HomePage()),
  58. ),
  59. GoRoute(
  60. path: RoutePath.scanPage,
  61. pageBuilder: (context, state) => CupertinoPage(
  62. child: ScanPage(title: state.extra as String),
  63. ),
  64. ),
  65. GoRoute(
  66. path: RoutePath.userPage,
  67. pageBuilder: (context, state) => CupertinoPage(
  68. child: UserPage(user: state.extra as MaxKeyUser?),
  69. ),
  70. ),
  71. GoRoute(
  72. path: RoutePath.settingsPage,
  73. pageBuilder: (context, state) =>
  74. const CupertinoPage(child: SettingsPage()),
  75. ),
  76. ],
  77. );
  78. // const _supportedLocales = <Locale>[
  79. // Locale('en', 'US'),
  80. // // generic Chinese 'zh'
  81. // Locale.fromSubtags(languageCode: 'zh'),
  82. // // generic simplified Chinese 'zh_Hans'
  83. // Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'),
  84. // // generic traditional Chinese 'zh_Hant'
  85. // Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'),
  86. // // 'zh_Hans_CN'
  87. // Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN'),
  88. // // 'zh_Hant_TW'
  89. // Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'TW'),
  90. // // 'zh_Hant_HK'
  91. // Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'HK'),
  92. // ];