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.
725 lines
31 KiB
Dart
725 lines
31 KiB
Dart
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:hmg_patient_app/config/config.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/check_user_status_reponse.dart';
|
|
import 'package:hmg_patient_app/models/Authentication/check_user_status_req.dart';
|
|
import 'package:hmg_patient_app/models/Authentication/checkpatient_for_registration.dart';
|
|
import 'package:hmg_patient_app/models/Authentication/register_info_response.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/font_utils.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/drawer/langauge_picker.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
|
|
_RegisterNew createState() => _RegisterNew();
|
|
}
|
|
|
|
class _RegisterNew extends State<RegisterNew> {
|
|
final nationalIDorFile = TextEditingController();
|
|
final phoneController = TextEditingController();
|
|
Country selectedCountry = Country.saudiArabia;
|
|
OTPType? otpType;
|
|
bool isTermsAccepted = false;
|
|
DateTime? selectedDOB;
|
|
CheckUserStatusResponse? nHICData;
|
|
|
|
final int loginType = LoginType.loginType;
|
|
late String mobileNo;
|
|
|
|
// String countryCode = '966';
|
|
var isHijri;
|
|
|
|
final util = Utils();
|
|
bool isButtonDisabled = true;
|
|
final authService = new AuthProvider();
|
|
final sharedPref = new AppSharedPreferences();
|
|
late PageController _controller;
|
|
late bool isLoading;
|
|
String? LoginTokenID;
|
|
bool isDubai = false;
|
|
final intl.DateFormat dateFormat = intl.DateFormat('dd/MM/yyyy');
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = new PageController();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
changePageViewIndex(pageIndex) {
|
|
_controller.jumpToPage(pageIndex);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AppScaffold(
|
|
appBarTitle: TranslationBase.of(context).register,
|
|
isShowDecPage: false,
|
|
isShowAppBar: true,
|
|
isshowBackButton: true,
|
|
showNewAppBar: true,
|
|
backgroundColor: Color(0xffF8F8F8),
|
|
showNewAppBarTitle: false,
|
|
showDropDown: true,
|
|
isShowLanguageChanger: true,
|
|
appBarIcons: [],
|
|
dropDownList: [],
|
|
resizeToAvoidBottomInset: true,
|
|
dropDownIndexChange: (value) {
|
|
Utils.changeAppLanguage(context: context);
|
|
},
|
|
body: GestureDetector(
|
|
onTap: () {
|
|
FocusScope.of(context).unfocus();
|
|
},
|
|
child: ScrollConfiguration(
|
|
behavior: ScrollConfiguration.of(context).copyWith(overscroll: false, physics: const ClampingScrollPhysics()),
|
|
child: NotificationListener<OverscrollIndicatorNotification>(
|
|
onNotification: (notification) {
|
|
notification.disallowIndicator();
|
|
return true;
|
|
},
|
|
child: SingleChildScrollView(
|
|
physics: ClampingScrollPhysics(),
|
|
padding: EdgeInsets.only(
|
|
left: 24,
|
|
right: 24,
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Utils.showLottie(
|
|
context: context,
|
|
assetPath: 'assets/animations/lottie/register.json',
|
|
width: MediaQuery.of(context).size.width * 0.45,
|
|
height: MediaQuery.of(context).size.height * 0.22,
|
|
fit: BoxFit.cover,
|
|
repeat: true),
|
|
SizedBox(height: 8),
|
|
Text(
|
|
TranslationBase.of(context).prepareToElevate,
|
|
textScaler: TextScaler.linear(MediaQuery.textScalerOf(context).scale(1)),
|
|
style: context.dynamicTextStyle(
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xff2B353E),
|
|
letterSpacing: -0.4,
|
|
height: 40 / 28,
|
|
),
|
|
),
|
|
SizedBox(height: 24),
|
|
Directionality(
|
|
textDirection: Directionality.of(context),
|
|
child: Container(
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(24)),
|
|
padding: EdgeInsets.only(left: 16, right: 16, top: 0, bottom: 0),
|
|
child: Column(
|
|
children: [
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: newInputWidget(
|
|
TranslationBase.of(context).country,
|
|
TranslationBase.of(context).ksa,
|
|
nationalIDorFile,
|
|
isEnable: true,
|
|
prefix: null,
|
|
hasSelection: true,
|
|
dropdownItems: Country.values.map((e) => context.selectedLanguage == "ar" ? e.nameArabic : e.displayName).toList(),
|
|
selectedValue: context.selectedLanguage == "ar" ? selectedCountry.nameArabic : selectedCountry.displayName,
|
|
selectionType: SelectionType.dropdown,
|
|
onChange: (val) {
|
|
if (val != null) {
|
|
print(val);
|
|
setState(() {
|
|
selectedCountry = CountryExtension.fromDisplayName(val);
|
|
});
|
|
}
|
|
},
|
|
isBorderAllowed: false,
|
|
isAllowLeadingIcon: true,
|
|
hasSelectionCustomIcon: true,
|
|
removePadding: true,
|
|
isLeadingCountry: true,
|
|
isAllowRadius: false,
|
|
padding: const EdgeInsets.only(top: 8, bottom: 8, left: 0, right: 0),
|
|
selectionCustomIcon: "assets/images/svg/arrow-down.svg",
|
|
leadingIcon: selectedCountry.iconPath,
|
|
).withVerticalPadding(8),
|
|
),
|
|
Divider(height: 1),
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: newInputWidget(TranslationBase.of(context).nationalIdNumber, "1xxxxxxxx", nationalIDorFile,
|
|
isEnable: true,
|
|
prefix: null,
|
|
removePadding: true,
|
|
isAllowRadius: false,
|
|
hasSelection: false,
|
|
isBorderAllowed: false,
|
|
isAllowLeadingIcon: true,
|
|
padding: const EdgeInsets.only(top: 8, bottom: 8, left: 0, right: 0),
|
|
leadingIcon: "assets/images/svg/student-card.svg", onChange: (value) {
|
|
print(value);
|
|
}).withVerticalPadding(8),
|
|
),
|
|
Divider(height: 1),
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: newInputWidget(TranslationBase.of(context).dob, "11 July, 1994", nationalIDorFile,
|
|
isEnable: true,
|
|
prefix: null,
|
|
hasSelection: true,
|
|
removePadding: true,
|
|
isBorderAllowed: false,
|
|
isAllowLeadingIcon: true,
|
|
hasSelectionCustomIcon: true,
|
|
selectionType: SelectionType.calendar,
|
|
selectedValue: selectedDOB != null ? Utils.formatDateToDisplay(selectedDOB.toString()) : null,
|
|
selectionCustomIcon: "assets/images/svg/calendar.svg",
|
|
lang: context.selectedLanguage,
|
|
padding: const EdgeInsets.only(top: 8, bottom: 8, left: 0, right: 0),
|
|
leadingIcon: "assets/images/svg/birthday-cake.svg", onChange: (value) {
|
|
selectedDOB = DateTime.parse(value!);
|
|
setState(() {});
|
|
}, onCalendarTypeChanged: (bool value) {
|
|
if (value) {
|
|
isHijri = 0;
|
|
} else {
|
|
isHijri = 1;
|
|
}
|
|
}).withVerticalPadding(8),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 25),
|
|
GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
isTermsAccepted = !isTermsAccepted;
|
|
});
|
|
},
|
|
child: Row(
|
|
children: [
|
|
AnimatedContainer(
|
|
duration: const Duration(milliseconds: 200),
|
|
height: 24,
|
|
width: 24,
|
|
decoration: BoxDecoration(
|
|
color: isTermsAccepted ? const Color(0xFFE92227) : Colors.transparent,
|
|
borderRadius: BorderRadius.circular(6),
|
|
border: Border.all(
|
|
color: isTermsAccepted ? const Color(0xFFE92227) : Colors.grey,
|
|
width: 2,
|
|
),
|
|
),
|
|
child: isTermsAccepted ? const Icon(Icons.check, size: 16, color: Colors.white) : null,
|
|
),
|
|
SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
TranslationBase.of(context).iAcceptTermsConditions,
|
|
style: context.dynamicTextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color(0xFF2E3039)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 25),
|
|
CustomButton(
|
|
text: TranslationBase.of(context).register,
|
|
icon: "assets/images/svg/note-edit.svg",
|
|
onPressed: () {
|
|
// bool isValid = Utils.validateIqama(nationalIDorFile.text);
|
|
if (nationalIDorFile == null) {
|
|
Utils.showErrorToast(TranslationBase.of(context).pleaseEnterNationalId);
|
|
return;
|
|
}
|
|
if (selectedCountry == null) {
|
|
Utils.showErrorToast(TranslationBase.of(context).pleaseSelectCountry);
|
|
return;
|
|
}
|
|
|
|
if (selectedDOB == null) {
|
|
Utils.showErrorToast(TranslationBase.of(context).pleaseSelectDOB);
|
|
return;
|
|
}
|
|
if (!isTermsAccepted) {
|
|
Utils.showErrorToast(TranslationBase.of(context).pleaseAcceptTermsConditions);
|
|
return;
|
|
}
|
|
|
|
if (phoneController != null) {
|
|
phoneController.clear();
|
|
}
|
|
|
|
showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
isDismissible: false,
|
|
backgroundColor: Colors.transparent,
|
|
builder: (bottomSheetContext) => Padding(
|
|
padding: EdgeInsets.only(bottom: MediaQuery.of(bottomSheetContext).viewInsets.bottom),
|
|
child: SingleChildScrollView(
|
|
child: GenericBottomSheet(
|
|
countryCode: selectedCountry.countryCode,
|
|
initialPhoneNumber: "",
|
|
textController: phoneController,
|
|
onChange: (String? value) {
|
|
mobileNo = value!;
|
|
},
|
|
buttons: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
child: CustomButton(
|
|
text: TranslationBase.of(context).sendOTPSMS,
|
|
onPressed: () {
|
|
int? val = Utils.onOtpBtnPressed(OTPType.sms, mobileNo);
|
|
registerUser(val);
|
|
},
|
|
backgroundColor: CustomColors.bgRedColor,
|
|
borderColor: CustomColors.bgRedBorderColor,
|
|
textColor: Colors.white,
|
|
icon: "assets/images/svg/message.svg",
|
|
),
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: AppText(
|
|
TranslationBase.of(context).oR,
|
|
fontSize: 16,
|
|
fontFamily: context.fontFamily,
|
|
color: Color(0xFF2E3039),
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 10, top: 10),
|
|
child: CustomButton(
|
|
text: TranslationBase.of(context).sendOTPWHATSAPP,
|
|
onPressed: () {
|
|
int? val = Utils.onOtpBtnPressed(OTPType.whatsapp, mobileNo);
|
|
registerUser(val);
|
|
// if (val != null) checkUserAuthentication(val);
|
|
},
|
|
backgroundColor: Colors.white,
|
|
borderColor: Color(0xFF2E3039),
|
|
textColor: Color(0xFF2E3039),
|
|
icon: "assets/images/svg/whatsapp.svg",
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
fontFamily: context.fontFamily,
|
|
),
|
|
SizedBox(height: 14),
|
|
Center(
|
|
child: RichText(
|
|
textAlign: TextAlign.center,
|
|
text: TextSpan(
|
|
style: context.dynamicTextStyle(
|
|
color: Colors.black,
|
|
fontSize: 16,
|
|
height: 26 / 16,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
children: <TextSpan>[
|
|
TextSpan(text: TranslationBase.of(context).alreadyHaveAccount, style: context.dynamicTextStyle()),
|
|
TextSpan(text: " "),
|
|
TextSpan(
|
|
text: TranslationBase.of(context).loginNow,
|
|
style: context.dynamicTextStyle(
|
|
color: CustomColors.bgRedColor,
|
|
fontSize: 16,
|
|
height: 26 / 16,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
recognizer: TapGestureRecognizer()
|
|
..onTap = () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 30),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
));
|
|
}
|
|
|
|
Widget showProgress({String? title, String? status, Color? color, bool isNeedBorder = true}) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 26,
|
|
height: 26,
|
|
decoration: containerRadius(color!, 200),
|
|
child: Icon(
|
|
Icons.done,
|
|
color: Colors.white,
|
|
size: 16,
|
|
),
|
|
),
|
|
if (isNeedBorder)
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: mDivider(Colors.grey),
|
|
)),
|
|
],
|
|
),
|
|
mHeight(8),
|
|
Text(
|
|
title!,
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.44,
|
|
),
|
|
),
|
|
mHeight(2),
|
|
Container(
|
|
padding: EdgeInsets.all(5),
|
|
decoration: containerRadius(color.withOpacity(0.2), 4),
|
|
child: Text(
|
|
status!,
|
|
style: TextStyle(
|
|
fontSize: 8,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.32,
|
|
color: color,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
);
|
|
}
|
|
|
|
void registerUser(int? value) {
|
|
otpType = value == 1 ? OTPType.sms : OTPType.whatsapp;
|
|
// OTPType.sms ? 1 : 2;
|
|
print("Country: ${selectedCountry.name}");
|
|
print("nationalId: ${nationalIDorFile.text}");
|
|
print("DOB: ${selectedDOB}");
|
|
if (value == 1) {
|
|
print("OTP sent successfully to ${mobileNo} using SMS");
|
|
} else {
|
|
print("OTP sent successfully to ${mobileNo} using Whatsapp");
|
|
}
|
|
|
|
// mobileNo = phoneController.text;
|
|
startRegistration(value);
|
|
|
|
// Navigator.of(context).push(FadePage(page: RegisterNewStep2()));
|
|
}
|
|
|
|
startRegistration(type) {
|
|
// if (isButtonDisabled == false) {
|
|
var request = CheckPatientForRegistration();
|
|
|
|
request.patientMobileNumber = int.parse(mobileNo);
|
|
request.zipCode = selectedCountry.countryCode;
|
|
request.patientOutSA = selectedCountry.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 ?? 0;
|
|
// request.tokenID = LoginTokenID;
|
|
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 {
|
|
final intl.DateFormat dateFormat = intl.DateFormat('dd/MM/yyyy');
|
|
nRequest['forRegister'] = true;
|
|
nRequest['isRegister'] = true;
|
|
nRequest["PatientIdentificationID"] = nRequest["PatientIdentificationID"].toString();
|
|
request.dob = isHijri == 1 ? selectedDOB!.toString() : dateFormat.format(selectedDOB!);
|
|
nRequest['isHijri'] = isHijri;
|
|
sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, nRequest);
|
|
sharedPref.setString(LOGIN_TOKEN_ID, response['LogInTokenID']);
|
|
if (request.patientOutSA == 0) {
|
|
this.chekUserData(response['LogInTokenID'], type); // ظ ;
|
|
} else {
|
|
sendActivationCode(type, response['LogInTokenID'], null);
|
|
}
|
|
}
|
|
} 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);
|
|
//}
|
|
}
|
|
}
|
|
|
|
chekUserData(loginToken, int type) {
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
var request = CheckUserStatusRequest();
|
|
request.patientIdentificationID = nationalIDorFile.text;
|
|
request.dOB = isHijri == 1 ? selectedDOB!.toString() : dateFormat.format(selectedDOB!);
|
|
request.isHijri = isHijri;
|
|
request.patientOutSA = selectedCountry.countryCode == '966' ? 0 : 1;
|
|
|
|
this.authService.checkUserStatus(request).then((result) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
if (result is Map) {
|
|
RegisterInfoResponse? resultSet;
|
|
|
|
CheckUserStatusResponse res = CheckUserStatusResponse.fromJson(result as Map<String, dynamic>);
|
|
nHICData = res;
|
|
sharedPref.setObject(NHIC_DATA, res.toJson());
|
|
resultSet = RegisterInfoResponse.fromJson(res.toJson());
|
|
|
|
// widget.changePageViewIndex!(1),
|
|
// Navigator.of(context).push(FadePage(page: ConfirmLogin(changePageViewIndex: widget.changePageViewIndex, fromRegistration: true))),
|
|
sendActivationCode(type, loginToken, resultSet);
|
|
} else {
|
|
AppToast.showErrorToast(message: result != null ? result : TranslationBase.of(context).somethingWentWrong);
|
|
}
|
|
});
|
|
}
|
|
|
|
sendActivationCode(type, loginTokenID, RegisterInfoResponse? nHICData) async {
|
|
LoginTokenID = loginTokenID;
|
|
var request = authService.getCommonRequest(
|
|
registerd_data: null,
|
|
deviceToken: DEVICE_TOKEN,
|
|
mobileNumber: int.parse(mobileNo),
|
|
zipCode: selectedCountry.countryCode,
|
|
patientOutSA: selectedCountry.countryCode == "966" ? 0 : 1,
|
|
loginTokenID: LoginTokenID,
|
|
selectedOption: type,
|
|
user: SelectDeviceIMEIRES());
|
|
request.isRegister = true;
|
|
request.dob = isHijri == 1 ? selectedDOB!.toString() : dateFormat.format(selectedDOB!);
|
|
request.sMSSignature = await SMSOTP.getSignature();
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
if (selectedCountry.countryCode == "966") {
|
|
request.healthId = nHICData!.healthId;
|
|
request.nationalID = nHICData.idNumber;
|
|
request.patientIdentificationID = nHICData.idNumber;
|
|
} else {
|
|
request.nationalID = nationalIDorFile.text;
|
|
request.patientIdentificationID = nationalIDorFile.text;
|
|
}
|
|
request.isHijri = isHijri ?? 0;
|
|
request.oTPSendType = type;
|
|
await this.authService.sendActivationCodeRegister(request).then((result) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
if (result != null && result['isSMSSent'] == true) {
|
|
print(result);
|
|
// LoginTokenID = result["LogInTokenID"];
|
|
startSMSService(type);
|
|
}
|
|
}).catchError((r) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
AppToast.showErrorToast(message: r);
|
|
});
|
|
}
|
|
|
|
checkActivationCode({value, type}) async {
|
|
// Navigator.pop(context);
|
|
// GifLoaderDialogUtils.showMyDialog(context);
|
|
var request = authService.getCommonRequest(
|
|
registerd_data: null,
|
|
deviceToken: DEVICE_TOKEN,
|
|
mobileNumber: int.parse(mobileNo),
|
|
zipCode: selectedCountry.countryCode,
|
|
patientOutSA: selectedCountry.countryCode == "966" ? 0 : 1,
|
|
loginTokenID: LoginTokenID,
|
|
selectedOption: type,
|
|
user: SelectDeviceIMEIRES());
|
|
dynamic res;
|
|
// if (healthId != null || isDubai) {
|
|
// if (isDubai) {
|
|
// request['DOB'] = dob;
|
|
// }
|
|
request.dob = isHijri == 1 ? selectedDOB!.toString() : dateFormat.format(selectedDOB!);
|
|
if (selectedCountry.countryCode == "966") {
|
|
request.healthId = nHICData!.healthId!;
|
|
}
|
|
request.isHijri = isHijri ?? 0;
|
|
request.nationalID = selectedCountry.countryCode == "966" ? nHICData!.idNumber : nationalIDorFile.text;
|
|
request.patientIdentificationID = selectedCountry.countryCode == "966" ? nHICData!.idNumber : nationalIDorFile.text;
|
|
request.isRegister = true;
|
|
|
|
authService
|
|
.checkActivationCodeRegister(request.toJson(), value)
|
|
.then((result) => {
|
|
res = result,
|
|
if (result is Map)
|
|
{
|
|
result = CheckActivationCode.fromJson(result as Map<String, dynamic>),
|
|
|
|
//next registration page navigate from here.
|
|
Navigator.of(context).push(
|
|
FadePage(page: RegisterNewStep2(nHICData, request)),
|
|
)
|
|
|
|
// // 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, localContext: context);
|
|
}),
|
|
// 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, type: type);
|
|
// },
|
|
// () => {
|
|
// Navigator.pop(context),
|
|
// },
|
|
// ).displayDialog(context);
|
|
// }
|
|
|
|
startSMSService(type) {
|
|
late SMSOTP smsOtp; // Declare the variable first
|
|
smsOtp = SMSOTP(
|
|
context,
|
|
type,
|
|
mobileNo,
|
|
(code) {
|
|
smsOtp.dispose(); // Now we can reference it
|
|
this.checkActivationCode(value: code, type: type);
|
|
},
|
|
() {
|
|
smsOtp.dispose(); // Now we can reference it
|
|
Navigator.pop(context);
|
|
},
|
|
);
|
|
smsOtp.displayDialog(context);
|
|
}
|
|
}
|