LocaleNotifier
unknown
dart
2 years ago
3.8 kB
11
Indexable
import 'package:base_architecture/data_layer/models/locale_model.dart';
import 'package:base_architecture/data_layer/models/radio_model.dart';
import 'package:base_architecture/presentation/pages/main/main_page.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
class LocaleNotifier extends ChangeNotifier {
int? localindex;
setLocalindex(int? newvalue) {
localindex = newvalue;
notifyListeners();
}
var _index = 0;
bool isArabic =
navigatorKey.currentContext!.locale.toString() == 'ar' ? true : false;
bool isEnglish =
navigatorKey.currentContext!.locale.toString() == 'en' ? true : false;
bool isHebrew =
navigatorKey.currentContext!.locale.toString() == 'he' ? true : false;
setToArabic() {
print('ar');
isArabic = true;
isEnglish = false;
isHebrew = false;
notifyListeners();
}
setToEnglish() {
print('en');
isEnglish = true;
isArabic = false;
isHebrew = false;
notifyListeners();
}
setToHebrew() {
print('he');
isHebrew = true;
isArabic = false;
isEnglish = false;
notifyListeners();
}
saveAllLanguage() {
if (isArabic) {
navigatorKey.currentContext!.setLocale(
const Locale('ar'),
);
} else if (isEnglish) {
navigatorKey.currentContext!.setLocale(
const Locale('en'),
);
} else if (isHebrew) {
navigatorKey.currentContext!.setLocale(
const Locale('he'),
);
} else {
navigatorKey.currentContext!.setLocale(
const Locale('en'),
);
}
notifyListeners();
}
final List<LocaleModel> _appLocales = [
LocaleModel(
localeName: 'العربية',
localeValue: 'ar',
),
LocaleModel(
localeName: 'English',
localeValue: 'en',
),
];
final List<LocaleModel> _allAppLocales = [
LocaleModel(
localeName: 'العربية',
localeValue: 'ar',
),
LocaleModel(
localeName: 'English',
localeValue: 'en',
),
LocaleModel(
localeName: 'עברית',
localeValue: 'he',
),
];
LocaleModel? selectedLocale = LocaleModel(
localeName: navigatorKey.currentContext!.locale.toString() == 'ar'
? 'العربية'
: navigatorKey.currentContext!.locale.toString() == 'en'
? 'English'
: navigatorKey.currentContext!.locale.toString() == 'he'
? 'עברית'
: 'ss',
localeValue: navigatorKey.currentContext!.locale == const Locale('ar')
? 'ar'
: navigatorKey.currentContext!.locale == const Locale('en')
? 'en'
: 'he',
);
setSelectedLocale(LocaleModel newValue) {
selectedLocale = newValue;
notifyListeners();
}
List<LocaleModel> get appLocales => _appLocales;
List<LocaleModel> get allAppLocales => _allAppLocales;
cancelAllSelectedLanguage() {
if (navigatorKey.currentContext!.locale == const Locale('ar')) {
setToArabic();
} else if (navigatorKey.currentContext!.locale == const Locale('en')) {
setToEnglish();
} else if (navigatorKey.currentContext!.locale == const Locale('he')) {
setToHebrew();
} else {
setToEnglish();
}
notifyListeners();
}
onBoardingSaveLanguage(String locale) {
if (locale == 'ar') {
setToArabic();
navigatorKey.currentContext!.setLocale(
const Locale('ar'),
);
} else if (locale == 'en') {
setToEnglish();
navigatorKey.currentContext!.setLocale(
const Locale('en'),
);
} else if (locale == 'he') {
setToHebrew();
navigatorKey.currentContext!.setLocale(
const Locale('he'),
);
} else {
setToEnglish();
}
notifyListeners();
}
}
Editor is loading...