Files
Remever/lib/services/core/lang_service.dart
2025-03-03 20:59:42 +03:00

43 lines
1.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}