95 lines
2.2 KiB
Dart
95 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../constant/box_name.dart';
|
|
import '../../main.dart';
|
|
import '../themes/themes.dart';
|
|
|
|
class LocaleController extends GetxController {
|
|
Locale? language;
|
|
String countryCode = '';
|
|
void restartApp() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
ThemeData appTheme = themeEnglish;
|
|
|
|
changeLang(String langcode) {
|
|
Locale locale;
|
|
switch (langcode) {
|
|
case "ar":
|
|
locale = const Locale("ar");
|
|
appTheme = themeArabic;
|
|
break;
|
|
case "en":
|
|
locale = const Locale("en");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "tr":
|
|
locale = const Locale("tr");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "fr":
|
|
locale = const Locale("fr");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "it":
|
|
locale = const Locale("it");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "de":
|
|
locale = const Locale("de");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "el":
|
|
locale = const Locale("el");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "es":
|
|
locale = const Locale("es");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "fa":
|
|
locale = const Locale("fa");
|
|
appTheme = themeArabic;
|
|
break;
|
|
case "zh":
|
|
locale = const Locale("zh");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "ru":
|
|
locale = const Locale("ru");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
case "hi":
|
|
locale = const Locale("hi");
|
|
appTheme = themeEnglish;
|
|
break;
|
|
default:
|
|
locale = Locale(Get.deviceLocale!.languageCode);
|
|
appTheme = themeEnglish;
|
|
break;
|
|
}
|
|
|
|
box.write(BoxName.lang, langcode);
|
|
Get.changeTheme(appTheme);
|
|
Get.updateLocale(locale);
|
|
restartApp();
|
|
update();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
String? storedLang = box.read(BoxName.lang);
|
|
if (storedLang == null) {
|
|
// Use device language if no language is stored
|
|
storedLang = Get.deviceLocale!.languageCode;
|
|
box.write(BoxName.lang, storedLang);
|
|
}
|
|
|
|
changeLang(storedLang);
|
|
|
|
super.onInit();
|
|
}
|
|
}
|