diff --git a/lib/core/enum/CalenderType.dart b/lib/core/enum/CalenderType.dart new file mode 100644 index 00000000..51f98512 --- /dev/null +++ b/lib/core/enum/CalenderType.dart @@ -0,0 +1,4 @@ +enum CalenderType{ + Gregorian, + Hijri, +} \ No newline at end of file diff --git a/lib/screens/patients/register_patient/RegisterConfirmationPatientPage.dart b/lib/screens/patients/register_patient/RegisterConfirmationPatientPage.dart index af861294..1f0a743f 100644 --- a/lib/screens/patients/register_patient/RegisterConfirmationPatientPage.dart +++ b/lib/screens/patients/register_patient/RegisterConfirmationPatientPage.dart @@ -63,8 +63,7 @@ class _RegisterConfirmationPatientPageState TextEditingController middleNameAr; TextEditingController lastNameAr; TextEditingController emailAddressController; - TextEditingController langController = TextEditingController( - text: "English"); + TextEditingController langController = TextEditingController(text: "English"); int selectedLang = 1; @override @@ -397,10 +396,13 @@ class _RegisterConfirmationPatientPageState widget.model.getPatientInfoResponseModel.dateOfBirth); String wellFormat = "${dateFormat.day}\/${dateFormat.month}\/${dateFormat.year}"; - print(dateFormat.toUtc().toString()); + print( + dateFormat.toUtc().toString(), + ); HijriCalendar hijriDate = HijriCalendar.fromDate( - new DateTime(dateFormat.year, dateFormat.month, - dateFormat.day)); + new DateTime( + dateFormat.year, dateFormat.month, dateFormat.day), + ); // return ; GifLoaderDialogUtils.showMyDialog(context); @@ -664,7 +666,6 @@ class _RegisterConfirmationPatientPageState groupValue: selectedLang, onChanged: (value) { setSelectedLang(value); - }, activeColor: Colors.red, ), @@ -682,10 +683,11 @@ class _RegisterConfirmationPatientPageState ); }); } - setSelectedLang(lang){ + + setSelectedLang(lang) { setState(() { selectedLang = lang; - langController.text = lang==1?"English": "العربيه"; + langController.text = lang == 1 ? "English" : "العربيه"; }); Navigator.of(context).pop(); } diff --git a/lib/screens/patients/register_patient/RegisterSearchPatientPage.dart b/lib/screens/patients/register_patient/RegisterSearchPatientPage.dart index 432842d3..2afc593e 100644 --- a/lib/screens/patients/register_patient/RegisterSearchPatientPage.dart +++ b/lib/screens/patients/register_patient/RegisterSearchPatientPage.dart @@ -20,6 +20,10 @@ import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/country_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; @@ -54,8 +58,10 @@ class _RegisterSearchPatientPageState extends State { TextEditingController(text: "1062938285"); String idError; - DateTime _birthDate; + DateTime _birthDateInGregorian; String birthdateError; + var birthDateInHijri = new HijriCalendar.now(); + CalenderType calenderType = CalenderType.Gregorian; @override void initState() { @@ -178,15 +184,44 @@ class _RegisterSearchPatientPageState extends State { 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: _birthDate != null - ? "${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "yyyy/MM/dd")}" - : null, + dropDownText: getBirthdate(), enabled: false, isTextFieldHasSuffix: true, - validationError: _birthDate == null && isSubmitted + validationError: _birthDateInGregorian == null && isSubmitted ? TranslationBase.of(context).emptyMessage : null, suffixIcon: IconButton( @@ -197,12 +232,29 @@ class _RegisterSearchPatientPageState extends State { onPressed: null, ), onClick: () { - if (_birthDate == null) { - _birthDate = DateTime.now(); + if (_birthDateInGregorian == null) { + _birthDateInGregorian = DateTime.now(); } - _selectDate(context, _birthDate, (picked) { + _selectDate(context, _birthDateInGregorian, + (dynamic selectedDate) { setState(() { - _birthDate = picked; + 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); + } }); }); }, @@ -276,13 +328,14 @@ class _RegisterSearchPatientPageState extends State { patientOutSA: 0, generalid: GENERAL_ID, dOB: - "${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "yyyy/MM/dd")}"); + "${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, + patientIdentificationID: "1062938285", + // _idController.text, isHijri: 0, isDentalAllowedBackend: false, patientOutSA: 0, @@ -319,23 +372,41 @@ class _RegisterSearchPatientPageState extends State { _phoneController.text.isNotEmpty && _idController.text != null && _idController.text.isNotEmpty && - _birthDate != null) { + _birthDateInGregorian != null) { return true; } return false; } Future _selectDate(BuildContext context, DateTime dateTime, - Function(DateTime picked) updateDate) async { - final DateTime picked = await showDatePicker( - context: context, - initialDate: dateTime, - firstDate: DateTime(DateTime.now().year - 150), - lastDate: DateTime(DateTime.now().year + 150), - initialEntryMode: DatePickerEntryMode.calendar, - ); - if (picked != null && picked != dateTime) { - updateDate(picked); + 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); + } } } @@ -359,4 +430,18 @@ class _RegisterSearchPatientPageState extends State { }, ); } + + getBirthdate() { + + if (calenderType == CalenderType.Hijri) { + return birthDateInHijri != null + ? "$birthDateInHijri" + : null; + }else{ + return _birthDateInGregorian != null + ? "${AppDateUtils.convertStringToDateFormat(_birthDateInGregorian.toString(), "yyyy/MM/dd")}" + : null; + } + + } } diff --git a/pubspec.lock b/pubspec.lock index 3080216d..3e9968d3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -575,12 +575,19 @@ packages: source: hosted version: "1.0.6" hijri: - dependency: "direct main" + dependency: transitive description: name: hijri url: "https://pub.dartlang.org" source: hosted version: "2.0.3" + hijri_picker: + dependency: "direct main" + description: + name: hijri_picker + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" html: dependency: "direct main" description: @@ -699,7 +706,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.4" + version: "1.3.0-nullsafety.3" mime: dependency: transitive description: @@ -1033,7 +1040,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.2" + version: "1.10.0-nullsafety.1" sticky_headers: dependency: "direct main" description: @@ -1238,5 +1245,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.10.2 <=2.11.0-213.1.beta" + dart: ">=2.10.2 <2.11.0" flutter: ">=1.22.2 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 485e8ae6..23d6a2aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -104,7 +104,8 @@ dependencies: badges: ^1.1.4 # Hijri - hijri: ^2.0.0 +# hijri: ^2.0.3 + hijri_picker: ^2.0.0