You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PatientApp-KKUMC/lib/core/viewModels/project_view_model.dart

95 lines
2.6 KiB
Dart

import 'dart:async';
import 'package:connectivity/connectivity.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';
4 years ago
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
class ProjectViewModel extends BaseViewModel {
4 years ago
// Platform Bridge
PlatformBridge platformBridge() {
4 years ago
return PlatformBridge.shared();
4 years ago
}
AppSharedPreferences sharedPref = AppSharedPreferences();
4 years ago
Locale _appLocale = Locale('ar');
String currentLanguage = 'ar';
bool _isArabic = false;
bool isInternetConnection = true;
bool isLoading = false;
bool isError = false;
String error = '';
4 years ago
dynamic searchvalue;
bool isLogin
= false;
4 years ago
4 years ago
dynamic get searchValue => searchvalue;
4 years ago
Locale get appLocal => _appLocale;
4 years ago
LocaleType get localeType => isArabic ? LocaleType.en : LocaleType.ar;
4 years ago
bool get isArabic => _isArabic;
4 years ago
4 years ago
// BaseViewModel baseViewModel = locator<BaseViewModel>()
StreamSubscription subscription;
ProjectViewModel() {
4 years ago
// PlatformBridge.init(context); // Moved to 'main.dart' due to context availability
loadSharedPrefLanguage();
4 years ago
subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
switch (result) {
case ConnectivityResult.wifi:
isInternetConnection = true;
break;
case ConnectivityResult.mobile:
isInternetConnection = true;
break;
case ConnectivityResult.none:
isInternetConnection = false;
break;
}
notifyListeners();
});
}
Future loadSharedPrefLanguage() async {
4 years ago
currentLanguage = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
_appLocale = Locale(currentLanguage);
_isArabic = currentLanguage == 'ar';
notifyListeners();
}
void changeLanguage(String lan) {
if (lan != "en" && currentLanguage != lan) {
_appLocale = Locale("ar");
_isArabic = true;
currentLanguage = 'ar';
sharedPref.setString(APP_LANGUAGE, 'ar');
} else if (lan != "ar" && currentLanguage != lan) {
_appLocale = Locale("en");
_isArabic = false;
currentLanguage = 'en';
sharedPref.setString(APP_LANGUAGE, 'en');
}
notifyListeners();
}
@override
void dispose() {
if (subscription != null) subscription.cancel();
super.dispose();
}
4 years ago
setSearchValue(data) {
searchvalue = data;
notifyListeners();
}
}