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.
diplomatic-quarter/lib/pages/login/register.dart

389 lines
16 KiB
Dart

4 years ago
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
4 years ago
import 'package:diplomaticquarterapp/config/size_config.dart';
4 years ago
import 'package:diplomaticquarterapp/models/Authentication/check_user_status_reponse.dart';
import 'package:diplomaticquarterapp/models/Authentication/check_user_status_req.dart';
import 'package:diplomaticquarterapp/models/Authentication/checkpatient_for_registration.dart';
import 'package:diplomaticquarterapp/pages/login/confirm-login.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/login/login-type.dart';
4 years ago
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/dialogs/alert_dialog.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/mobile-no/mobile_no.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
4 years ago
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart' as intl;
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
4 years ago
class Register extends StatefulWidget {
final Function changePageViewIndex;
const Register({Key key, this.changePageViewIndex}) : super(key: key);
4 years ago
@override
_Register createState() => _Register();
}
class _Register extends State<Register> {
4 years ago
final nationalIDorFile = TextEditingController();
4 years ago
final int loginType = LoginType.loginType;
4 years ago
String mobileNo;
String countryCode = '966';
4 years ago
var isHijri;
4 years ago
final util = Utils();
4 years ago
DateTime selectedDate;
TextEditingController dob = TextEditingController();
TextEditingController dobEn = TextEditingController();
4 years ago
bool isButtonDisabled = true;
final authService = new AuthProvider();
final sharedPref = new AppSharedPreferences();
bool isLoading;
4 years ago
@override
Widget build(BuildContext context) {
return AppScaffold(
appBarTitle: TranslationBase.of(context).register,
isShowAppBar: false,
isShowDecPage: false,
showNewAppBar: false,
showNewAppBarTitle: true,
4 years ago
body: SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 30),
height: SizeConfig.realScreenHeight * .9,
width: SizeConfig.realScreenWidth,
child: Column(children: <Widget>[
Expanded(
child: ListView(
padding: EdgeInsets.zero,
physics: BouncingScrollPhysics(),
children: [
SizedBox(height: 10),
Padding(
padding: EdgeInsets.all(10),
child: Text(
TranslationBase.of(context).enterNationalId,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.64, height: 23 / 16),
)),
SizedBox(height: 10),
PhoneNumberSelectorWidget(onNumberChange: (value) => {mobileNo = value, validateForm()}, onCountryChange: (value) => countryCode = value),
SizedBox(height: 12),
Directionality(textDirection: TextDirection.ltr, child: inputWidget(TranslationBase.of(context).nationalIdNumber, "Xxxxxxxxx", nationalIDorFile)),
SizedBox(height: 20),
Row(
children: <Widget>[
Expanded(
child: Row(
4 years ago
children: <Widget>[
Radio(
value: 1,
groupValue: isHijri,
onChanged: (value) {
setState(() {
isHijri = value;
});
validateForm();
},
4 years ago
),
Text(TranslationBase.of(context).hijriDate),
],
),
),
Expanded(
child: Row(
children: <Widget>[
Radio(
value: 0,
groupValue: isHijri,
onChanged: (value) {
setState(() {
isHijri = value;
});
validateForm();
},
4 years ago
),
Text(TranslationBase.of(context).gregorianDate),
4 years ago
],
),
),
],
),
Row(children: <Widget>[
Container(
width: SizeConfig.realScreenWidth * .9,
child: isHijri == 1
? Directionality(
textDirection: TextDirection.ltr,
child: inputWidget(TranslationBase.of(context).dob, "DD/MM/YYYYY", dob,
isNumber: false,
suffix: Icon(
Icons.calendar_today,
size: 16,
)))
: Container(
child: InkWell(
onTap: () {
if (isHijri != null) _selectDate(context);
},
child: Directionality(
textDirection: TextDirection.ltr,
child: inputWidget(TranslationBase.of(context).dob, "DD/MM/YYYYY", dobEn,
isNumber: false,
isEnable: false,
suffix: Icon(
Icons.calendar_today,
size: 16,
)))))),
])
],
),
),
]),
)),
bottomSheet: Container(
width: double.maxFinite,
height: 80.0,
child: Row(
children: [
Expanded(
child: Padding(
padding: EdgeInsets.all(10), child: DefaultButton(TranslationBase.of(context).cancel, () => {Navigator.of(context).pop()}, textColor: Colors.white, color: Color(0xffD02127))),
),
Expanded(
child: Padding(
padding: EdgeInsets.all(10),
child: DefaultButton(TranslationBase.of(context).next, () => {startRegistration()}, textColor: Colors.white, color: isButtonDisabled == true ? Colors.grey : Color(0xff359846))),
),
],
)));
4 years ago
}
Future<Null> _selectDate(BuildContext context) async {
DatePicker.showDatePicker(
context,
showTitleActions: true,
minTime: DateTime(DateTime.now().year - 100, 1, 1),
maxTime: DateTime.now(),
onConfirm: (date) {
selectedDate = date;
setState(() {
final intl.DateFormat dateFormat = intl.DateFormat('dd/MM/yyyy');
dobEn.text = dateFormat.format(date);
});
},
currentTime: DateTime.now(),
);
}
Widget inputWidget(String _labelText, String _hintText, TextEditingController _controller, {String prefix, bool isEnable = true, bool hasSelection = false, bool isNumber = true, Icon suffix}) {
return Container(
padding: EdgeInsets.only(left: 16, right: 16, bottom: 15, top: 15),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
border: Border.all(
color: Color(0xffefefef),
width: 1,
),
),
child: InkWell(
onTap: hasSelection ? () {} : null,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_labelText,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: Color(0xff2B353E),
letterSpacing: -0.44,
),
),
TextField(
enabled: isEnable,
scrollPadding: EdgeInsets.zero,
keyboardType: isNumber ? TextInputType.number : TextInputType.datetime,
controller: _controller,
onChanged: (value) => {validateForm()},
style: TextStyle(
fontSize: 14,
height: 21 / 14,
fontWeight: FontWeight.w400,
color: Color(0xff2B353E),
letterSpacing: -0.44,
),
decoration: InputDecoration(
isDense: true,
hintText: _hintText,
hintStyle: TextStyle(
fontSize: 14,
height: 21 / 14,
fontWeight: FontWeight.w400,
color: Color(0xff575757),
letterSpacing: -0.56,
),
prefixIconConstraints: BoxConstraints(minWidth: 50),
prefixIcon: prefix == null
? null
: Text(
"+" + prefix,
style: TextStyle(
fontSize: 14,
height: 21 / 14,
fontWeight: FontWeight.w500,
color: Color(0xff2E303A),
letterSpacing: -0.56,
),
),
contentPadding: EdgeInsets.zero,
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
],
),
),
if (hasSelection) Icon(Icons.keyboard_arrow_down_outlined),
if (suffix != null) suffix
],
),
),
);
4 years ago
}
4 years ago
startRegistration() {
final intl.DateFormat dateFormat = intl.DateFormat('dd/MM/yyyy');
4 years ago
if (isButtonDisabled == false) {
var request = CheckPatientForRegistration();
request.patientMobileNumber = int.parse(mobileNo);
request.zipCode = countryCode;
request.patientOutSA = countryCode == '966' ? 0 : 1;
4 years ago
request.patientIdentificationID = int.parse(nationalIDorFile.text);
request.patientID = 0;
request.isRegister = true;
request.dob = isHijri == 1 ? dob.text : dateFormat.format(selectedDate);
request.isHijri = isHijri;
4 years ago
this.checkPatientForRegisteration(request);
}
}
checkPatientForRegisteration(request) {
4 years ago
GifLoaderDialogUtils.showMyDialog(context);
this.authService.checkPatientForRegisteration(request).then((response) => {checkUserStatus(response, request)}).catchError((err) {
4 years ago
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: Register())),
},
4 years ago
cancelFunction: () => {ConfirmDialog.closeAlertDialog(context)});
dialog.showAlertDialog(context);
});
4 years ago
}
void validateForm() {
if (util.validateIDBox(nationalIDorFile.text, loginType) == true &&
mobileNo.length >= 9 &&
util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true &&
isHijri != null &&
(dobEn.text != null || dob.text != null)) {
4 years ago
setState(() {
isButtonDisabled = false;
});
} else {
setState(() {
isButtonDisabled = true;
});
}
}
checkUserStatus(response, CheckPatientForRegistration request) async {
4 years ago
GifLoaderDialogUtils.hideDialog(context);
4 years ago
if (response is Map) {
var nRequest = request.toJson();
nRequest['LogInTokenID'] = response['LogInTokenID'];
if (response['hasFile'] == true) {
// AppToast.showErrorToast(message: response['ErrorEndUserMessage']);
4 years ago
AlertDialogBox(
context: context,
confirmMessage: response['ErrorEndUserMessage'],
okText: TranslationBase.of(context).ok,
okFunction: () {
AlertDialogBox.closeAlertDialog(context);
Navigator.of(context).pop();
}).showAlertDialog(context);
4 years ago
} else {
nRequest['forRegister'] = true;
nRequest['isRegister'] = true;
nRequest["PatientIdentificationID"] = nRequest["PatientIdentificationID"].toString();
4 years ago
sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, nRequest);
sharedPref.setString(LOGIN_TOKEN_ID, response['LogInTokenID']);
4 years ago
this.chekUserData(response['LogInTokenID']);
}
} else {
// if (response['ErrorCode'] == '-986') {
4 years ago
//AppToast.showErrorToast(message: response);
AlertDialogBox(
context: context,
confirmMessage: response,
okText: TranslationBase.of(context).ok,
okFunction: () {
AlertDialogBox.closeAlertDialog(context);
Navigator.of(context).pop();
}).showAlertDialog(context);
//}
4 years ago
}
}
chekUserData(loginToken) {
// let m = hijri(this.dateOfBirth).locale('en');
// // const dateHijri = m.format('iDD/iMM/iYYYY');
// const request = {
// PatientIdentificationID: this.id.toString(),
// // TokenID: token,
// DOB: this.dateOption === '1' ? this.dateOfBirth : moment(this.dateOfBirth).format('DD/MM/YYYY'),
// IsHijri: Number(this.dateOption)
// }
3 years ago
final intl.DateFormat dateFormat = intl.DateFormat('dd/MM/yyyy');
GifLoaderDialogUtils.showMyDialog(context);
4 years ago
var request = CheckUserStatusRequest();
request.patientIdentificationID = nationalIDorFile.text;
request.dOB = isHijri == 1 ? dob.text : dateFormat.format(selectedDate);
4 years ago
request.isHijri = isHijri;
request.patientOutSA = countryCode == '966' ? 0 : 1;
this.authService.checkUserStatus(request).then((result) => {
GifLoaderDialogUtils.hideDialog(context),
4 years ago
if (result is Map)
{
result = CheckUserStatusResponse.fromJson(result),
sharedPref.setObject(NHIC_DATA, result),
Navigator.of(context).push(FadePage(page: ConfirmLogin(changePageViewIndex: widget.changePageViewIndex))),
4 years ago
}
else
{AppToast.showErrorToast(message: result ? result : TranslationBase.of(context).somethingWentWrong)}
4 years ago
});
}
4 years ago
}