Skip to content

Commit

Permalink
Fixed 'system locale'
Browse files Browse the repository at this point in the history
  • Loading branch information
ferraridamiano committed Oct 22, 2023
1 parent 63e4aff commit 6c93226
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:io';
import 'package:converterpro/models/order.dart';
import 'package:converterpro/models/properties_list.dart';
import 'package:converterpro/models/settings.dart';
Expand Down Expand Up @@ -117,8 +118,6 @@ class MyApp extends ConsumerWidget {
errorBuilder: (context, state) => const ErrorPage(),
);

bool deviceLocaleSetted = false;

const Color fallbackColorSchemeSeed = Colors.blue;

return DynamicColorBuilder(
Expand Down Expand Up @@ -154,6 +153,19 @@ class MyApp extends ConsumerWidget {
);

return Consumer(builder: (context, ref, child) {
Locale? settingsLocale = ref.watch(CurrentLocale.provider).valueOrNull;
String deviceLocaleLanguageCode = Platform.localeName.split('_')[0];
Locale appLocale;
if (settingsLocale != null) {
appLocale = settingsLocale;
} else if (mapLocale.keys
.map((Locale locale) => locale.languageCode)
.contains(deviceLocaleLanguageCode)) {
appLocale = Locale(deviceLocaleLanguageCode);
} else {
appLocale = const Locale('en');
}

return MaterialApp.router(
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
Expand All @@ -168,21 +180,7 @@ class MyApp extends ConsumerWidget {
: darkTheme,
supportedLocales: mapLocale.keys,
localizationsDelegates: AppLocalizations.localizationsDelegates,
localeResolutionCallback:
(Locale? deviceLocale, Iterable<Locale> supportedLocales) {
if (!deviceLocaleSetted) {
//context.read<AppModel>().deviceLocale = deviceLocale;
deviceLocaleSetted = true;
}
if (supportedLocales
.map((Locale locale) => locale.languageCode)
.contains(deviceLocale?.languageCode)) {
return deviceLocale;
}
return const Locale('en');
},
locale: ref.watch(CurrentLocale.provider).valueOrNull ??
const Locale('en'),
locale: appLocale,
);
});
});
Expand Down

0 comments on commit 6c93226

Please sign in to comment.