mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 03:26:24 +00:00
Locale switch (#200)
* Add function to set app locale * Setting for selecting app language - Adds requirement for "flutter_localized_locales" - Change main app to stateless * Reload entire app tree when language is changed * Update release notes * linting
This commit is contained in:
parent
19ff6eb526
commit
9559b8602e
7 changed files with 158 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import "dart:async";
|
||||
import "dart:ui";
|
||||
|
||||
import "package:inventree/l10n/supported_locales.dart";
|
||||
import "package:path_provider/path_provider.dart";
|
||||
import "package:sembast/sembast.dart";
|
||||
import "package:sembast/sembast_io.dart";
|
||||
|
|
@ -83,6 +85,26 @@ class InvenTreeSettingsManager {
|
|||
|
||||
Future<Database> get _db async => InvenTreePreferencesDB.instance.database;
|
||||
|
||||
Future<Locale?> getSelectedLocale() async {
|
||||
final String locale_name = await getValue("customLocale", "") as String;
|
||||
|
||||
if (locale_name.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (var locale in supported_locales) {
|
||||
if (locale.toString() == locale_name) {
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
|
||||
// No matching locale found
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> setSelectedLocale(Locale? locale) async {
|
||||
await setValue("customLocale", locale?.toString() ?? "");
|
||||
}
|
||||
|
||||
Future<void> removeValue(String key) async {
|
||||
await store.record(key).delete(await _db);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue