|
|
|
|
@ -1,24 +1,36 @@
|
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
|
import 'package:hmg_patient_app/config/shared_pref_kay.dart';
|
|
|
|
|
import 'package:hmg_patient_app/config/size_config.dart';
|
|
|
|
|
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
|
|
|
|
|
import 'package:hmg_patient_app/models/Authentication/check_activation_code_response.dart';
|
|
|
|
|
import 'package:hmg_patient_app/models/Authentication/check_paitent_authentication_req.dart';
|
|
|
|
|
import 'package:hmg_patient_app/models/Authentication/checkpatient_for_registration.dart';
|
|
|
|
|
import 'package:hmg_patient_app/new_ui/otp/otp_validation_bootmsheet_widget.dart';
|
|
|
|
|
import 'package:hmg_patient_app/pages/AlHabibMedicalService/health_calculator/carbs/carbs.dart';
|
|
|
|
|
import 'package:hmg_patient_app/pages/login/login-type.dart';
|
|
|
|
|
import 'package:hmg_patient_app/pages/login/register-info.dart';
|
|
|
|
|
import 'package:hmg_patient_app/pages/login/register.dart';
|
|
|
|
|
import 'package:hmg_patient_app/pages/login/register_new_step_2.dart';
|
|
|
|
|
import 'package:hmg_patient_app/pages/login/welcome.dart';
|
|
|
|
|
import 'package:hmg_patient_app/services/authentication/auth_provider.dart';
|
|
|
|
|
import 'package:hmg_patient_app/theme/colors.dart';
|
|
|
|
|
import 'package:hmg_patient_app/uitl/app_shared_preferences.dart';
|
|
|
|
|
import 'package:hmg_patient_app/uitl/app_toast.dart';
|
|
|
|
|
import 'package:hmg_patient_app/uitl/gif_loader_dialog_utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
|
|
|
|
|
import 'package:hmg_patient_app/uitl/utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app/uitl/utils_new.dart';
|
|
|
|
|
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:hmg_patient_app/widgets/otp/sms-popup.dart';
|
|
|
|
|
import 'package:hmg_patient_app/widgets/text/app_texts_widget.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import '../../models/Authentication/select_device_imei_res.dart';
|
|
|
|
|
import '../../widgets/dialogs/alert_dialog.dart';
|
|
|
|
|
import '../../widgets/dialogs/confirm_dialog.dart';
|
|
|
|
|
import '../../widgets/transitions/fade_page.dart';
|
|
|
|
|
import 'package:intl/intl.dart' as intl;
|
|
|
|
|
|
|
|
|
|
class RegisterNew extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
@ -29,6 +41,7 @@ class _RegisterNew extends State<RegisterNew> {
|
|
|
|
|
final nationalIDorFile = TextEditingController();
|
|
|
|
|
final phoneController = TextEditingController();
|
|
|
|
|
Country selectedCountry = Country.saudiArabia;
|
|
|
|
|
OTPType? otpType;
|
|
|
|
|
bool isTermsAccepted = false;
|
|
|
|
|
DateTime? selectedDOB;
|
|
|
|
|
|
|
|
|
|
@ -37,13 +50,13 @@ class _RegisterNew extends State<RegisterNew> {
|
|
|
|
|
String countryCode = '966';
|
|
|
|
|
var isHijri;
|
|
|
|
|
final util = Utils();
|
|
|
|
|
late String dob;
|
|
|
|
|
bool isButtonDisabled = true;
|
|
|
|
|
final authService = new AuthProvider();
|
|
|
|
|
final sharedPref = new AppSharedPreferences();
|
|
|
|
|
late PageController _controller;
|
|
|
|
|
late bool isLoading;
|
|
|
|
|
int _currentIndex = 0;
|
|
|
|
|
String? LoginTokenID;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
@ -492,7 +505,8 @@ class _RegisterNew extends State<RegisterNew> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void registerUser(int? value) {
|
|
|
|
|
//OTPType.sms ? 1 : 2;
|
|
|
|
|
otpType = value == 1 ? OTPType.sms : OTPType.whatsapp;
|
|
|
|
|
// OTPType.sms ? 1 : 2;
|
|
|
|
|
print("Country: ${selectedCountry.name}");
|
|
|
|
|
print("nationalId: ${nationalIDorFile.text}");
|
|
|
|
|
print("DOB: ${selectedDOB}");
|
|
|
|
|
@ -501,6 +515,183 @@ class _RegisterNew extends State<RegisterNew> {
|
|
|
|
|
} else {
|
|
|
|
|
print("OTP sent successfully to ${phoneController.text} using Whatsapp");
|
|
|
|
|
}
|
|
|
|
|
Navigator.of(context).push(FadePage(page: RegisterNewStep2()));
|
|
|
|
|
mobileNo = phoneController.text;
|
|
|
|
|
startRegistration(value);
|
|
|
|
|
// Navigator.of(context).push(FadePage(page: RegisterNewStep2()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startRegistration(type) {
|
|
|
|
|
final intl.DateFormat dateFormat = intl.DateFormat('dd/MM/yyyy');
|
|
|
|
|
// if (isButtonDisabled == false) {
|
|
|
|
|
var request = CheckPatientForRegistration();
|
|
|
|
|
|
|
|
|
|
request.patientMobileNumber = int.parse(mobileNo);
|
|
|
|
|
request.zipCode = countryCode;
|
|
|
|
|
request.patientOutSA = countryCode == '966' ? 0 : 1;
|
|
|
|
|
request.patientIdentificationID = int.parse(nationalIDorFile.text);
|
|
|
|
|
request.patientID = 0;
|
|
|
|
|
request.isRegister = true;
|
|
|
|
|
request.dob = isHijri == 1 ? selectedDOB!.toString() : dateFormat.format(selectedDOB!);
|
|
|
|
|
request.isHijri = isHijri;
|
|
|
|
|
this.checkPatientForRegisteration(registrationData: request, type: type);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkPatientForRegisteration({required CheckPatientForRegistration registrationData, type}) {
|
|
|
|
|
int languageID = Provider.of<ProjectViewModel>(context, listen: false).isArabic ? 1 : 2;
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
authService.checkPatientForRegisteration(registrationData, languageID).then((response) => {checkUserStatus(response, registrationData, type)}).catchError((err) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
ConfirmDialog dialog = new ConfirmDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
confirmMessage: err,
|
|
|
|
|
okText: TranslationBase.of(context).confirm,
|
|
|
|
|
cancelText: TranslationBase.of(context).cancel_nocaps,
|
|
|
|
|
okFunction: () => {
|
|
|
|
|
ConfirmDialog.closeAlertDialog(context),
|
|
|
|
|
Navigator.of(context).push(FadePage(page: RegisterNew())),
|
|
|
|
|
},
|
|
|
|
|
cancelFunction: () => {ConfirmDialog.closeAlertDialog(context)});
|
|
|
|
|
dialog.showAlertDialog(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkUserStatus(response, CheckPatientForRegistration request, type) async {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
if (response is Map) {
|
|
|
|
|
var nRequest = request.toJson();
|
|
|
|
|
nRequest['LogInTokenID'] = response['LogInTokenID'];
|
|
|
|
|
if (response['hasFile'] == true) {
|
|
|
|
|
ConfirmDialog dialog = new ConfirmDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
confirmMessage: response['ErrorEndUserMessage'],
|
|
|
|
|
okText: TranslationBase.of(context).ok,
|
|
|
|
|
cancelText: TranslationBase.of(context).cancel,
|
|
|
|
|
okFunction: () {
|
|
|
|
|
AlertDialogBox.closeAlertDialog(context);
|
|
|
|
|
sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, nRequest);
|
|
|
|
|
// LoginRegistration.loginMethod = type; // 1=NationalID, by default from Registration
|
|
|
|
|
Navigator.of(context).push(FadePage(page: WelcomeLogin()));
|
|
|
|
|
},
|
|
|
|
|
cancelFunction: () {})
|
|
|
|
|
.showAlertDialog(context);
|
|
|
|
|
} else {
|
|
|
|
|
sendActivationCode(type, nRequest['LogInTokenID']);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// if (response['ErrorCode'] == '-986') {
|
|
|
|
|
//AppToast.showErrorToast(message: response);
|
|
|
|
|
AlertDialogBox(
|
|
|
|
|
context: context,
|
|
|
|
|
confirmMessage: response,
|
|
|
|
|
okText: TranslationBase.of(context).ok,
|
|
|
|
|
okFunction: () {
|
|
|
|
|
AlertDialogBox.closeAlertDialog(context);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
}).showAlertDialog(context);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendActivationCode(type, loginTokenID) async {
|
|
|
|
|
LoginTokenID = loginTokenID;
|
|
|
|
|
var request = authService.getCommonRequest(
|
|
|
|
|
registerd_data: null,
|
|
|
|
|
deviceToken: null,
|
|
|
|
|
mobileNumber: mobileNo,
|
|
|
|
|
zipCode: selectedCountry.countryCode,
|
|
|
|
|
patientOutSA: selectedCountry.countryCode == "966" ? 0 : 1,
|
|
|
|
|
loginTokenID: LoginTokenID,
|
|
|
|
|
selectedOption: type,
|
|
|
|
|
user: SelectDeviceIMEIRES());
|
|
|
|
|
request.sMSSignature = await SMSOTP.getSignature();
|
|
|
|
|
// selectedOption = type;
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
// if (healthId != null || isDubai) {
|
|
|
|
|
// if (!isDubai) {
|
|
|
|
|
// request.dob = dob; //isHijri == 1 ? dob : dateFormat2.format(dateFormat.parse(dob));
|
|
|
|
|
// }
|
|
|
|
|
// request.healthId = healthId;
|
|
|
|
|
request.isHijri = isHijri;
|
|
|
|
|
await this.authService.sendActivationCodeRegister(request).then((result) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
if (result != null && result['isSMSSent'] == true) {
|
|
|
|
|
startSMSService(type);
|
|
|
|
|
}
|
|
|
|
|
}).catchError((r) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
AppToast.showErrorToast(message: r);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkActivationCode({value}) async {
|
|
|
|
|
// Navigator.pop(context);
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
var request = authService.getCommonRequest(
|
|
|
|
|
registerd_data: null,
|
|
|
|
|
deviceToken: null,
|
|
|
|
|
mobileNumber: mobileNo,
|
|
|
|
|
zipCode: selectedCountry.countryCode,
|
|
|
|
|
patientOutSA: selectedCountry.countryCode == "966" ? 0 : 1,
|
|
|
|
|
loginTokenID: LoginTokenID,
|
|
|
|
|
selectedOption: value,
|
|
|
|
|
user: SelectDeviceIMEIRES());
|
|
|
|
|
dynamic res;
|
|
|
|
|
// if (healthId != null || isDubai) {
|
|
|
|
|
// if (isDubai) {
|
|
|
|
|
// request['DOB'] = dob;
|
|
|
|
|
// }
|
|
|
|
|
// request['HealthId'] = healthId;
|
|
|
|
|
// request['IsHijri'] = isHijri;
|
|
|
|
|
|
|
|
|
|
authService
|
|
|
|
|
.checkActivationCodeRegister(request, value)
|
|
|
|
|
.then((result) => {
|
|
|
|
|
res = result,
|
|
|
|
|
if (result is Map)
|
|
|
|
|
{
|
|
|
|
|
result = CheckActivationCode.fromJson(result as Map<String, dynamic>),
|
|
|
|
|
// if (this.registerd_data != null && this.registerd_data.isRegister == true)
|
|
|
|
|
// {
|
|
|
|
|
// // if(widget.isDubai ==false){
|
|
|
|
|
// // widget.changePageViewIndex!(1),
|
|
|
|
|
// // if(widget.isDubai ==false){
|
|
|
|
|
//
|
|
|
|
|
// Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)),
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Navigator.of(context).pop(),
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context),
|
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
|
|
|
AppToast.showErrorToast(message: result);
|
|
|
|
|
}),
|
|
|
|
|
// projectViewModel.analytics.loginRegistration.login_fail(error: result),
|
|
|
|
|
// projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result),
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catchError((err) {
|
|
|
|
|
print(err);
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
|
|
|
AppToast.showErrorToast(message: err);
|
|
|
|
|
// startSMSService(tempType);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startSMSService(type) {
|
|
|
|
|
SMSOTP(
|
|
|
|
|
context,
|
|
|
|
|
type,
|
|
|
|
|
phoneController.text,
|
|
|
|
|
(value) {
|
|
|
|
|
this.checkActivationCode(value: value);
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
Navigator.pop(context),
|
|
|
|
|
},
|
|
|
|
|
).displayDialog(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|