import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/PatientRegistration/CheckPatientForRegistrationModel.dart'; import 'package:doctor_app_flutter/core/model/PatientRegistration/GetPatientInfoRequestModel.dart'; import 'package:doctor_app_flutter/core/model/PatientRegistration/PatientRegistrationModel.dart'; import 'package:doctor_app_flutter/core/viewModel/PatientRegistrationViewModel.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/util/date-utils.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/dialogs/dailog-list-select.dart'; import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart'; import 'package:flutter/material.dart'; import 'package:hijri/hijri_calendar.dart'; import 'package:hijri_picker/hijri_picker.dart'; import 'package:doctor_app_flutter/core/enum/CalenderType.dart'; import 'package:intl/intl.dart'; class RegisterSearchPatientPage extends StatefulWidget { final Function changePageViewIndex; final PatientRegistrationViewModel model; const RegisterSearchPatientPage( {Key key, this.changePageViewIndex, this.model}) : super(key: key); @override _RegisterSearchPatientPageState createState() => _RegisterSearchPatientPageState(); } class _RegisterSearchPatientPageState extends State { String countryError; dynamic _selectedCountry; bool isSubmitted = false; TextEditingController _phoneController = TextEditingController(text: "508079569"); TextEditingController _phoneCode = TextEditingController(text: "966"); String phoneError; TextEditingController _idController = TextEditingController(text: "1062938285"); String idError; DateTime _birthDateInGregorian; String birthdateError; var birthDateInHijri = new HijriCalendar.now(); CalenderType calenderType = CalenderType.Gregorian; @override Widget build(BuildContext context) { final screenSize = MediaQuery.of(context).size; /// TODO Elham* add transaltion return AppScaffold( baseViewModel: widget.model, isShowAppBar: false, body: Column( children: [ Expanded( child: Container( width: double.infinity, margin: EdgeInsets.all(16.0), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ AppText( "Please enter mobile number or Identification number", fontFamily: 'Poppins', fontSize: SizeConfig.textMultiplier * 2.2, fontWeight: FontWeight.w800, ), SizedBox( height: 10, ), AppTextFieldCustom( height: screenSize.height * 0.075, hintText: "Country", isTextFieldHasSuffix: true, validationError: countryError, dropDownText: _selectedCountry != null ? _selectedCountry['nameEn'] : "Saudi Arabia", enabled: false, ), SizedBox( height: 10, ), Row( children: [ Column( children: [ Container( width: MediaQuery.of(context).size.width * 0.28, child: AppTextFieldCustom( height: screenSize.height * 0.075, hintText: "Code", inputType: TextInputType.phone, controller: _phoneCode, validationError: phoneError, ), ), if (_phoneController.text.isEmpty && isSubmitted) SizedBox( height: 35, ) ], ), SizedBox( width: 10, ), Expanded( child: Container( // width: MediaQuery.of(context).size.width*0.7, child: AppTextFieldCustom( height: screenSize.height * 0.075, hintText: "Phone Number", inputType: TextInputType.phone, controller: _phoneController, validationError: _phoneController.text.isEmpty && isSubmitted ? TranslationBase.of(context).emptyMessage : null, ), ), ), ], ), SizedBox( height: 10, ), AppTextFieldCustom( height: screenSize.height * 0.075, hintText: "ID Number", inputType: TextInputType.phone, controller: _idController, validationError: _idController.text.isEmpty && isSubmitted ? TranslationBase.of(context).emptyMessage : null, ), SizedBox( height: 12, ), AppText( "Calender", fontSize: SizeConfig.textMultiplier * 1.8, fontWeight: FontWeight.w800, ), SizedBox( height: 10, ), Row( children: [ Expanded( child: RadioListTile( title: AppText("Gregorian"), value: CalenderType.Gregorian, groupValue: calenderType, onChanged: (CalenderType value) { setState(() { calenderType = value; }); }, ), ), Expanded( child: RadioListTile( title: AppText("Hijri"), value: CalenderType.Hijri, groupValue: calenderType, onChanged: (CalenderType value) { setState(() { calenderType = value; }); }, ), ), ], ), SizedBox( height: 10, ), AppTextFieldCustom( height: screenSize.height * 0.075, hintText: "Birthdate", dropDownText: getBirthdate(), enabled: false, isTextFieldHasSuffix: true, validationError: _birthDateInGregorian == null && isSubmitted ? TranslationBase.of(context).emptyMessage : null, suffixIcon: IconButton( icon: Icon( Icons.calendar_today, color: Colors.black, ), onPressed: null, ), onClick: () { if (_birthDateInGregorian == null) { _birthDateInGregorian = DateTime.now(); } _selectDate(context, _birthDateInGregorian, (dynamic selectedDate) { setState(() { if (calenderType == CalenderType.Hijri) { birthDateInHijri = selectedDate; _birthDateInGregorian = HijriCalendar().hijriToGregorian( birthDateInHijri.hYear, birthDateInHijri.hMonth, birthDateInHijri.hDay); print(_birthDateInGregorian); print(birthDateInHijri); } else { _birthDateInGregorian = selectedDate; birthDateInHijri = HijriCalendar() .gregorianToHijri( selectedDate.year, selectedDate.month, selectedDate.day); print(_birthDateInGregorian); print(birthDateInHijri); } }); }); }, ), ], ), ), ), ), ], ), bottomSheet: Container( height: 60, margin: EdgeInsets.symmetric(vertical: 16, horizontal: 16), child: Row( children: [ Expanded( child: Container( child: AppButton( title: TranslationBase.of(context).cancel, hasBorder: true, vPadding: 12, hPadding: 8, borderColor: Color(0xFFeaeaea), color: Color(0xFFeaeaea), fontColor: Colors.black, fontSize: 2.2, onPressed: () { Navigator.of(context).pop(); }, ), ), ), SizedBox( width: 8, ), Expanded( child: Container( child: AppButton( title: TranslationBase.of(context).next, hasBorder: true, vPadding: 12, hPadding: 8, borderColor: Color(0xFFB8382B), color: Color(0xFFB8382B), fontColor: Colors.white, fontSize: 2.0, onPressed: () async { setState(() { isSubmitted = true; }); if (isFormValid()) { GifLoaderDialogUtils.showMyDialog(context); CheckPatientForRegistrationModel checkPatientForRegistrationModel = CheckPatientForRegistrationModel( patientIdentificationID: int.parse(_idController.text), patientMobileNumber: int.parse(_phoneController.text), zipCode: _phoneCode.text, isHijri: 0, patientID: 0, isRegister: false, isDentalAllowedBackend: false, patientOutSA: 0, generalid: GENERAL_ID, dOB: "${AppDateUtils.convertStringToDateFormat(_birthDateInGregorian.toString(), "yyyy/MM/dd")}"); await widget.model.checkPatientForRegistration( checkPatientForRegistrationModel); GetPatientInfoRequestModel getPatientInfoRequestModel = GetPatientInfoRequestModel( //TODO Elham* this return the static to dynamic patientIdentificationID: "1062938285", //_idController.text, isHijri: 0, isDentalAllowedBackend: false, patientOutSA: 0, generalid: GENERAL_ID, sessionID: null, dOB: "31/07/1988", //"${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "dd/MM/yyyy")}" ); if (widget.model.state == ViewState.ErrorLocal) { Helpers.showErrorToast(widget.model.error); } else { await widget.model .getPatientInfo(getPatientInfoRequestModel); if (widget.model.state == ViewState.ErrorLocal) { Helpers.showErrorToast(widget.model.error); } else { widget.changePageViewIndex(1); } } GifLoaderDialogUtils.hideDialog(context); } }, ), ), ), ], ), ), ); } isFormValid() { if (_phoneController.text != null && _phoneController.text.isNotEmpty && _idController.text != null && _idController.text.isNotEmpty && _birthDateInGregorian != null) { return true; } return false; } Future _selectDate(BuildContext context, DateTime dateTime, Function(dynamic) updateDate) async { if (calenderType == CalenderType.Hijri) { HijriCalendar hijriDate = HijriCalendar.fromDate(DateTime.now()); final HijriCalendar pickedH = await showHijriDatePicker( context: context, initialDate: birthDateInHijri ?? hijriDate, lastDate: new HijriCalendar() ..hYear = hijriDate.hYear ..hMonth = hijriDate.hMonth ..hDay = hijriDate.hDay, firstDate: new HijriCalendar() ..hYear = 1438 ..hMonth = 12 ..hDay = 25, initialDatePickerMode: DatePickerMode.day, ); if (pickedH != null && birthDateInHijri != pickedH) updateDate(pickedH); } else { final DateTime picked = await showDatePicker( context: context, initialDate: dateTime ?? DateTime.now(), firstDate: DateTime(DateTime.now().year - 150), lastDate: DateTime.now(), initialEntryMode: DatePickerEntryMode.calendar, ); if (picked != null && picked != dateTime) { updateDate(picked); } } } void openListDialogField(String attributeName, String attributeValueId, List list, Function(dynamic selectedValue) okFunction) { ListSelectDialog dialog = ListSelectDialog( list: list, attributeName: attributeName, attributeValueId: attributeValueId, usingSearch: true, okText: TranslationBase.of(context).ok, okFunction: (selectedValue) { okFunction(selectedValue); }, ); showDialog( barrierDismissible: false, context: context, builder: (BuildContext context) { return dialog; }, ); } getBirthdate() { if (calenderType == CalenderType.Hijri) { return birthDateInHijri != null ? "$birthDateInHijri" : null; }else{ return _birthDateInGregorian != null ? "${AppDateUtils.convertStringToDateFormat(_birthDateInGregorian.toString(), "yyyy/MM/dd")}" : null; } } }