git-touch-android-ios-app/lib/app.dart

78 lines
2.7 KiB
Dart
Raw Permalink Normal View History

2022-09-24 09:36:22 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2020-01-14 11:13:07 +01:00
import 'package:flutter/cupertino.dart';
2022-09-11 19:54:07 +02:00
import 'package:flutter_gen/gen_l10n/S.dart';
2020-02-01 07:44:15 +01:00
import 'package:git_touch/models/auth.dart';
2020-01-14 11:13:07 +01:00
import 'package:git_touch/models/theme.dart';
2022-09-11 19:54:07 +02:00
import 'package:git_touch/router.dart';
2021-02-27 04:42:11 +01:00
import 'package:intl/locale.dart' as l;
2022-09-11 19:54:07 +02:00
import 'package:provider/provider.dart';
2020-01-14 11:13:07 +01:00
class MyApp extends StatelessWidget {
2022-09-24 07:22:07 +02:00
const MyApp({super.key});
2020-02-01 07:44:15 +01:00
@override
Widget build(BuildContext context) {
final auth = Provider.of<AuthModel>(context);
2021-02-14 06:01:09 +01:00
final theme = Provider.of<ThemeModel>(context);
2022-09-24 20:09:46 +02:00
return AntTheme(
2021-02-14 06:01:09 +01:00
key: auth.rootKey,
2022-09-24 20:09:46 +02:00
data: AntThemeData(brightness: theme.brightness),
child: Builder(
builder: (context) {
final antTheme = AntTheme.of(context);
return CupertinoApp.router(
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
theme: CupertinoThemeData(
brightness: theme.brightness,
primaryColor: antTheme.colorPrimary,
2022-10-04 14:18:04 +02:00
scaffoldBackgroundColor: antTheme.colorBox,
2022-09-24 20:09:46 +02:00
textTheme: CupertinoTextThemeData(
textStyle: TextStyle(
fontSize: antTheme.fontSizeMain,
color: antTheme.colorText,
),
),
),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
2022-10-08 20:19:28 +02:00
localeListResolutionCallback: (locales, supportedLocales) {
// 1. user set locale
// 2. system locale
try {
if (theme.locale != null) {
final intlLocale = l.Locale.parse(theme.locale!);
locales = [
Locale.fromSubtags(
languageCode: intlLocale.languageCode,
countryCode: intlLocale.countryCode,
scriptCode: intlLocale.scriptCode,
),
...locales!
];
}
} catch (err) {
print(err);
}
for (final locale in locales!) {
// this is necessary because Flutter only handles zh_Hans -> zh
// and would not handle non-exist language code
if (AppLocalizations.delegate.isSupported(locale)) {
return locale;
}
}
// 3. if none match, use the default
return supportedLocales.firstWhere((l) => l.languageCode == 'en');
},
2022-09-24 20:09:46 +02:00
);
},
2022-09-17 14:35:45 +02:00
),
2021-02-14 06:01:09 +01:00
);
2020-02-01 07:44:15 +01:00
}
2020-01-14 11:13:07 +01:00
}