first commit
This commit is contained in:
42
lib/services/core/lang_service.dart
Normal file
42
lib/services/core/lang_service.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:remever/common/resources.dart';
|
||||
import 'package:remever/common/storage.dart';
|
||||
import 'package:remever/i18n/strings.g.dart';
|
||||
import 'package:remever/interfaces/warmup_service.dart';
|
||||
|
||||
import 'core_service.dart';
|
||||
|
||||
///
|
||||
/// Сервис для работы с языками приложения
|
||||
///
|
||||
class LangService extends CoreService implements IWarmupService {
|
||||
///
|
||||
/// Установка языка при первом запуске
|
||||
///
|
||||
@override
|
||||
Future<void> init() async {
|
||||
final AppLocale deviceLocale = await LocaleSettings.useDeviceLocale();
|
||||
AppLocale? locale = hiveLang.get(StorageKeys.langCode);
|
||||
|
||||
if (locale == null) {
|
||||
LocaleSettings.setLocale(deviceLocale);
|
||||
|
||||
hiveLang.put(StorageKeys.langCode, deviceLocale);
|
||||
} else {
|
||||
LocaleSettings.setLocale(locale);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Получение текущей локали
|
||||
///
|
||||
AppLocale get locale =>
|
||||
hiveLang.get(StorageKeys.langCode, defaultValue: AppLocale.en)!;
|
||||
|
||||
///
|
||||
/// Запись и установка языка
|
||||
///
|
||||
Future<void> setLanguage(AppLocale locale) async {
|
||||
await hiveLang.put(StorageKeys.langCode, locale);
|
||||
LocaleSettings.setLocale(locale);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user