|
|
|
@ -405,10 +405,26 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
AppState().setMohemmWifiPassword = mohemmWifiPassword;
|
|
|
|
AppState().setMohemmWifiPassword = mohemmWifiPassword;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
|
|
|
if (firebaseToken == null || firebaseToken!.isEmpty || firebaseToken == "null") {
|
|
|
|
|
|
|
|
if (AppState().getDeviceToken != null && AppState().getDeviceToken!.isNotEmpty && AppState().getDeviceToken != "null") {
|
|
|
|
|
|
|
|
firebaseToken = AppState().getDeviceToken;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String saved = await Utils.getStringFromPrefs("P_DEP_DEVICE_TOKEN");
|
|
|
|
|
|
|
|
if (saved.isNotEmpty && saved != "null") {
|
|
|
|
|
|
|
|
firebaseToken = saved;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String effectiveTokenArg = (firebaseToken != null && firebaseToken!.isNotEmpty && firebaseToken != "null")
|
|
|
|
|
|
|
|
? firebaseToken!
|
|
|
|
|
|
|
|
: (AppState().getDeviceToken ?? "");
|
|
|
|
if (_autoLogin && loginInfo != null) {
|
|
|
|
if (_autoLogin && loginInfo != null) {
|
|
|
|
|
|
|
|
if (loginInfo!.deviceToken == null || loginInfo!.deviceToken!.isEmpty || loginInfo!.deviceToken == "null") {
|
|
|
|
|
|
|
|
loginInfo!.deviceToken = effectiveTokenArg;
|
|
|
|
|
|
|
|
}
|
|
|
|
Navigator.pushReplacementNamed(context, AppRoutes.verifyLastLogin, arguments: loginInfo);
|
|
|
|
Navigator.pushReplacementNamed(context, AppRoutes.verifyLastLogin, arguments: loginInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Navigator.pushNamed(context, AppRoutes.verifyLogin, arguments: "$firebaseToken");
|
|
|
|
Navigator.pushNamed(context, AppRoutes.verifyLogin, arguments: effectiveTokenArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Utils.saveStringFromPrefs(SharedPrefsConsts.password, password.text);
|
|
|
|
Utils.saveStringFromPrefs(SharedPrefsConsts.password, password.text);
|
|
|
|
} catch (ex) {
|
|
|
|
} catch (ex) {
|
|
|
|
@ -969,7 +985,14 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
if (checkOtpResponse?.authenticationTokenID != null && checkOtpResponse!.authenticationTokenID!.trim().isNotEmpty) {
|
|
|
|
if (checkOtpResponse?.authenticationTokenID != null && checkOtpResponse!.authenticationTokenID!.trim().isNotEmpty) {
|
|
|
|
Utils.saveStringFromPrefs("P_DEP_AUTHENTICATION_TOKEN_ID", checkOtpResponse.authenticationTokenID!.trim());
|
|
|
|
Utils.saveStringFromPrefs("P_DEP_AUTHENTICATION_TOKEN_ID", checkOtpResponse.authenticationTokenID!.trim());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Utils.saveStringFromPrefs("P_DEP_DEVICE_TOKEN", AppState().getIsHuawei ? AppState().getHuaweiPushToken : firebaseToken ?? "");
|
|
|
|
String tokenToSave = AppState().getIsHuawei
|
|
|
|
|
|
|
|
? AppState().getHuaweiPushToken
|
|
|
|
|
|
|
|
: ((firebaseToken != null && firebaseToken!.isNotEmpty && firebaseToken != "null")
|
|
|
|
|
|
|
|
? firebaseToken!
|
|
|
|
|
|
|
|
: (AppState().getDeviceToken ?? ""));
|
|
|
|
|
|
|
|
if (tokenToSave.isNotEmpty && tokenToSave != "null") {
|
|
|
|
|
|
|
|
Utils.saveStringFromPrefs("P_DEP_DEVICE_TOKEN", tokenToSave);
|
|
|
|
|
|
|
|
}
|
|
|
|
Utils.saveStringFromPrefs("P_DEP_LOGIN_TYPE", loginType.toString());
|
|
|
|
Utils.saveStringFromPrefs("P_DEP_LOGIN_TYPE", loginType.toString());
|
|
|
|
|
|
|
|
|
|
|
|
if (navigateToDashboard && ApiConsts.ISDependetLogin) {
|
|
|
|
if (navigateToDashboard && ApiConsts.ISDependetLogin) {
|
|
|
|
@ -977,6 +1000,30 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _ensureDeviceTokenLoaded() async {
|
|
|
|
|
|
|
|
if (firebaseToken == null || firebaseToken!.isEmpty || firebaseToken == "null") {
|
|
|
|
|
|
|
|
if (AppState().getDeviceToken != null && AppState().getDeviceToken!.isNotEmpty && AppState().getDeviceToken != "null") {
|
|
|
|
|
|
|
|
firebaseToken = AppState().getDeviceToken;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String saved = await Utils.getStringFromPrefs("P_DEP_DEVICE_TOKEN");
|
|
|
|
|
|
|
|
if (saved.isNotEmpty && saved != "null") {
|
|
|
|
|
|
|
|
firebaseToken = saved;
|
|
|
|
|
|
|
|
AppState().setDeviceToken = saved;
|
|
|
|
|
|
|
|
} else if (!AppState().getIsHuawei) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await Firebase.initializeApp();
|
|
|
|
|
|
|
|
String? tok = await FirebaseMessaging.instance.getToken();
|
|
|
|
|
|
|
|
if (tok != null && tok.isNotEmpty) {
|
|
|
|
|
|
|
|
firebaseToken = tok;
|
|
|
|
|
|
|
|
AppState().setDeviceToken = tok;
|
|
|
|
|
|
|
|
Utils.saveStringFromPrefs("P_DEP_DEVICE_TOKEN", tok);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (_) {}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (isAppOpenBySystem == null) {
|
|
|
|
if (isAppOpenBySystem == null) {
|
|
|
|
@ -992,7 +1039,11 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
// 13777
|
|
|
|
// 13777
|
|
|
|
// Ab12345cd
|
|
|
|
// Ab12345cd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isAppOpenBySystem!) checkFirebaseToken();
|
|
|
|
if (isAppOpenBySystem!) {
|
|
|
|
|
|
|
|
checkFirebaseToken();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_ensureDeviceTokenLoaded();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// username.text = "15444";
|
|
|
|
// username.text = "15444";
|
|
|
|
@ -1013,10 +1064,12 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
LocaleKeys.english.tr().toText14(color: AppState().isArabic(context) ? null : MyColors.textMixColor).onPress(() {
|
|
|
|
LocaleKeys.english.tr().toText14(color: AppState().isArabic(context) ? null : MyColors.textMixColor).onPress(() {
|
|
|
|
context.setLocale(const Locale("en", "US"));
|
|
|
|
context.setLocale(const Locale("en", "US"));
|
|
|
|
|
|
|
|
_ensureDeviceTokenLoaded();
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
Container(width: 1, color: MyColors.darkWhiteColor, height: 16, margin: const EdgeInsets.only(left: 10, right: 10)),
|
|
|
|
Container(width: 1, color: MyColors.darkWhiteColor, height: 16, margin: const EdgeInsets.only(left: 10, right: 10)),
|
|
|
|
LocaleKeys.arabic.tr().toText14(color: !AppState().isArabic(context) ? null : MyColors.textMixColor).onPress(() {
|
|
|
|
LocaleKeys.arabic.tr().toText14(color: !AppState().isArabic(context) ? null : MyColors.textMixColor).onPress(() {
|
|
|
|
context.setLocale(const Locale("ar", "SA"));
|
|
|
|
context.setLocale(const Locale("ar", "SA"));
|
|
|
|
|
|
|
|
_ensureDeviceTokenLoaded();
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|