diff --git a/lib/main.dart b/lib/main.dart index 23b79e6..9c1e5d6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,12 +4,14 @@ import 'package:arche/arche.dart'; import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:superuser/superuser.dart'; import 'package:system_fonts/system_fonts.dart'; import 'package:wslconfigurer/i18n/i18n.dart'; import 'package:wslconfigurer/models/config.dart'; import 'package:wslconfigurer/models/key.dart'; +import 'package:wslconfigurer/views/pages/doctor.dart'; import 'package:wslconfigurer/views/pages/manage.dart'; import 'package:wslconfigurer/views/pages/settings.dart'; import 'package:wslconfigurer/views/widgets/basic.dart'; @@ -68,6 +70,7 @@ class MyAppState extends State with RefreshMountedStateMixin { @override Widget build(BuildContext context) { var configs = ArcheBus.bus.of(); + var locale = configs.locale.getOr("en_US").split("_"); return DynamicColorBuilder( builder: (lightDynamic, darkDynamic) => MaterialApp( theme: ThemeData( @@ -88,6 +91,16 @@ class MyAppState extends State with RefreshMountedStateMixin { key: rootKey, ), ), + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: const [ + Locale("en", "US"), + Locale("zh", "CN"), + ], + locale: Locale(locale.first, locale.last), debugShowCheckedModeBanner: false, themeMode: configs.themeMode.getOrWrite(ThemeMode.system), ), @@ -173,9 +186,7 @@ class HomePageState extends State with RefreshMountedStateMixin { ).toItem(icon: const Icon(Icons.apps)), PageContainer( title: context.i18n.getOrKey("doctor"), - child: const Center( - child: Text("TODO"), - ), + child: const DoctorPage(), ).toItem(icon: const Icon(FontAwesomeIcons.userDoctor)), PageContainer( title: context.i18n.getOrKey("settings"), diff --git a/lib/views/pages/doctor.dart b/lib/views/pages/doctor.dart index e69de29..09d1d37 100644 --- a/lib/views/pages/doctor.dart +++ b/lib/views/pages/doctor.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; + +class DoctorPage extends StatefulWidget { + const DoctorPage({super.key}); + + @override + State createState() => _DoctorPageState(); +} + +class _DoctorPageState extends State { + @override + Widget build(BuildContext context) { + return const Column(); + } +} diff --git a/lib/views/pages/settings.dart b/lib/views/pages/settings.dart index 6480225..23a1d32 100644 --- a/lib/views/pages/settings.dart +++ b/lib/views/pages/settings.dart @@ -32,7 +32,7 @@ class _SettingsPageState extends State { var i18n = I18n(); await i18n.init(value); ArcheBus.bus.replace(i18n); - rootKey.currentState?.setState(() {}); + appKey.currentState?.refreshMounted(); setState(() {}); }, itemBuilder: (context) => context.i18n.avaiableLanguages.entries diff --git a/pubspec.lock b/pubspec.lock index 07cd71b..7da3030 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -150,6 +150,11 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_markdown: dependency: "direct main" description: @@ -200,6 +205,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0+1" + intl: + dependency: transitive + description: + name: intl + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf + url: "https://pub.dev" + source: hosted + version: "0.19.0" leak_tracker: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e0118a0..d12f5d6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,7 +30,9 @@ environment: dependencies: flutter: sdk: flutter - + flutter_localizations: + sdk: flutter + # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.6