Future loginUser(String phone, String password,
TextEditingController codeController) async {
String result = 'OK';
FocusManager.instance.primaryFocus?.unfocus();
_showUserProgress = true;
_userProgressText = 'Busy logging you in...please wait...';
notifyListeners();
phone = phone.replaceRange(0, 1, '+27');
print(phone);
Twilio.loginWithPhoneNumberAndPassword(phone, password).then((value) async {
String transactionId = value["transactionId"];
String? code = await showVerificationDialog(codeController);
if (code != null && code.compareTo('CANCEL') != 0) {
Twilio.loginWithCode(transactionId, code).then((value) {
if (value != null) {
print(value);
_currentUser = BackendlessUser.fromJson(value);
//Backendless.userService.setCurrentUser(_currentUser!);
print(value['user-token']);
Backendless.userService.setUserToken(value['user-token']);
}
_showUserProgress = false;
notifyListeners();
Get.off(() => const HomeAdmin());
showSnackBar(
title: 'User Authentication',
message:
'${_currentUser == null ? 'User' : _currentUser!.email} successfully authenticated!');
}).onError((error, stackTrace) {
print(getHumanReadableError(error.toString()));
showSnackBar(title: 'User Authentication', message: error.toString());
_showUserProgress = false;
notifyListeners();
});
} else {
showSnackBar(
title: 'Authenticate User',
message: 'Sorry, could not verify your phone number.');
_showUserProgress = false;
notifyListeners();
}
}).onError((error, stackTrace) {
print(getHumanReadableError(error.toString()));
showSnackBar(title: 'Here Authenticate User', message: error.toString());
_showUserProgress = false;
notifyListeners();
});
}
My login function. Like I said, login works perfectly, but the User does not stay logged in when using the normal Flutter SDK to check.