finish hijri calender

merge-requests/883/head
Elham Rababh 4 years ago
parent 8e85bb239e
commit 8d2b6e9b08

@ -63,8 +63,7 @@ class _RegisterConfirmationPatientPageState
TextEditingController middleNameAr; TextEditingController middleNameAr;
TextEditingController lastNameAr; TextEditingController lastNameAr;
TextEditingController emailAddressController; TextEditingController emailAddressController;
TextEditingController langController = TextEditingController( TextEditingController langController = TextEditingController(text: "English");
text: "English");
int selectedLang = 1; int selectedLang = 1;
@override @override
@ -397,10 +396,13 @@ class _RegisterConfirmationPatientPageState
widget.model.getPatientInfoResponseModel.dateOfBirth); widget.model.getPatientInfoResponseModel.dateOfBirth);
String wellFormat = String wellFormat =
"${dateFormat.day}\/${dateFormat.month}\/${dateFormat.year}"; "${dateFormat.day}\/${dateFormat.month}\/${dateFormat.year}";
print(dateFormat.toUtc().toString()); print(
dateFormat.toUtc().toString(),
);
HijriCalendar hijriDate = HijriCalendar.fromDate( HijriCalendar hijriDate = HijriCalendar.fromDate(
new DateTime(dateFormat.year, dateFormat.month, new DateTime(
dateFormat.day)); dateFormat.year, dateFormat.month, dateFormat.day),
);
// return ; // return ;
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
@ -664,7 +666,6 @@ class _RegisterConfirmationPatientPageState
groupValue: selectedLang, groupValue: selectedLang,
onChanged: (value) { onChanged: (value) {
setSelectedLang(value); setSelectedLang(value);
}, },
activeColor: Colors.red, activeColor: Colors.red,
), ),
@ -682,10 +683,11 @@ class _RegisterConfirmationPatientPageState
); );
}); });
} }
setSelectedLang(lang){
setSelectedLang(lang) {
setState(() { setState(() {
selectedLang = lang; selectedLang = lang;
langController.text = lang==1?"English": "العربيه"; langController.text = lang == 1 ? "English" : "العربيه";
}); });
Navigator.of(context).pop(); Navigator.of(context).pop();
} }

@ -22,14 +22,14 @@ import 'package:flutter/material.dart';
import 'package:hijri/hijri_calendar.dart'; import 'package:hijri/hijri_calendar.dart';
import 'package:hijri_picker/hijri_picker.dart'; import 'package:hijri_picker/hijri_picker.dart';
import 'package:doctor_app_flutter/core/enum/CalenderType.dart'; import 'package:doctor_app_flutter/core/enum/CalenderType.dart';
import 'package:intl/intl.dart';
class RegisterSearchPatientPage extends StatefulWidget { class RegisterSearchPatientPage extends StatefulWidget {
final Function changePageViewIndex; final Function changePageViewIndex;
final PatientRegistrationViewModel model; final PatientRegistrationViewModel model;
const RegisterSearchPatientPage({Key key, this.changePageViewIndex, this.model}) const RegisterSearchPatientPage(
{Key key, this.changePageViewIndex, this.model})
: super(key: key); : super(key: key);
@override @override
@ -42,25 +42,25 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
dynamic _selectedCountry; dynamic _selectedCountry;
bool isSubmitted = false; bool isSubmitted = false;
TextEditingController _phoneController =
TextEditingController _phoneController = TextEditingController(text: "508079569"); TextEditingController(text: "508079569");
TextEditingController _phoneCode = TextEditingController(text: "966"); TextEditingController _phoneCode = TextEditingController(text: "966");
String phoneError; String phoneError;
TextEditingController _idController = TextEditingController(text: "1062938285"); TextEditingController _idController =
TextEditingController(text: "1062938285");
String idError; String idError;
DateTime _birthDate; DateTime _birthDateInGregorian;
String birthdateError; String birthdateError;
var selectedHijriDate = new HijriCalendar.now(); var birthDateInHijri = new HijriCalendar.now();
CalenderType calenderType = CalenderType.Gregorian; CalenderType calenderType = CalenderType.Gregorian;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size; final screenSize = MediaQuery.of(context).size;
/// TODO Elham* add transaltion /// TODO Elham* add transaltion
return AppScaffold( return AppScaffold(
@ -112,14 +112,15 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
validationError: phoneError, validationError: phoneError,
), ),
), ),
if(_phoneController if (_phoneController.text.isEmpty && isSubmitted)
.text.isEmpty && SizedBox(
isSubmitted height: 35,
) )
SizedBox(height: 35,)
], ],
), ),
SizedBox(width: 10,), SizedBox(
width: 10,
),
Expanded( Expanded(
child: Container( child: Container(
// width: MediaQuery.of(context).size.width*0.7, // width: MediaQuery.of(context).size.width*0.7,
@ -128,12 +129,10 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
hintText: "Phone Number", hintText: "Phone Number",
inputType: TextInputType.phone, inputType: TextInputType.phone,
controller: _phoneController, controller: _phoneController,
validationError: _phoneController validationError:
.text.isEmpty && _phoneController.text.isEmpty && isSubmitted
isSubmitted ? TranslationBase.of(context).emptyMessage
? TranslationBase.of(context) : null,
.emptyMessage
: null,
), ),
), ),
), ),
@ -147,11 +146,8 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
hintText: "ID Number", hintText: "ID Number",
inputType: TextInputType.phone, inputType: TextInputType.phone,
controller: _idController, controller: _idController,
validationError: _idController validationError: _idController.text.isEmpty && isSubmitted
.text.isEmpty && ? TranslationBase.of(context).emptyMessage
isSubmitted
? TranslationBase.of(context)
.emptyMessage
: null, : null,
), ),
SizedBox( SizedBox(
@ -199,15 +195,11 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
AppTextFieldCustom( AppTextFieldCustom(
height: screenSize.height * 0.075, height: screenSize.height * 0.075,
hintText: "Birthdate", hintText: "Birthdate",
dropDownText: _birthDate != null dropDownText: getBirthdate(),
? "${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "yyyy/MM/dd")}"
: null,
enabled: false, enabled: false,
isTextFieldHasSuffix: true, isTextFieldHasSuffix: true,
validationError: _birthDate == null && validationError: _birthDateInGregorian == null && isSubmitted
isSubmitted ? TranslationBase.of(context).emptyMessage
? TranslationBase.of(context)
.emptyMessage
: null, : null,
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: Icon(
@ -217,12 +209,29 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
onPressed: null, onPressed: null,
), ),
onClick: () { onClick: () {
if (_birthDate == null) { if (_birthDateInGregorian == null) {
_birthDate = DateTime.now(); _birthDateInGregorian = DateTime.now();
} }
_selectDate(context, _birthDate, (picked) { _selectDate(context, _birthDateInGregorian,
(dynamic selectedDate) {
setState(() { 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);
}
}); });
}); });
}, },
@ -274,42 +283,44 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
setState(() { setState(() {
isSubmitted = true; isSubmitted = true;
}); });
if(isFormValid()) { if (isFormValid()) {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
CheckPatientForRegistrationModel CheckPatientForRegistrationModel
checkPatientForRegistrationModel = checkPatientForRegistrationModel =
CheckPatientForRegistrationModel( CheckPatientForRegistrationModel(
patientIdentificationID: patientIdentificationID:
int.parse(_idController.text), int.parse(_idController.text),
patientMobileNumber: patientMobileNumber:
int.parse(_phoneController.text), int.parse(_phoneController.text),
zipCode: _phoneCode.text, zipCode: _phoneCode.text,
isHijri: 0, isHijri: 0,
patientID: 0, patientID: 0,
isRegister: false, isRegister: false,
isDentalAllowedBackend: false, isDentalAllowedBackend: false,
patientOutSA: 0, patientOutSA: 0,
generalid: GENERAL_ID, generalid: GENERAL_ID,
dOB: dOB:
"${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "yyyy/MM/dd")}"); "${AppDateUtils.convertStringToDateFormat(_birthDateInGregorian.toString(), "yyyy/MM/dd")}");
await widget.model.checkPatientForRegistration( await widget.model.checkPatientForRegistration(
checkPatientForRegistrationModel); checkPatientForRegistrationModel);
GetPatientInfoRequestModel getPatientInfoRequestModel = GetPatientInfoRequestModel getPatientInfoRequestModel =
GetPatientInfoRequestModel( GetPatientInfoRequestModel(
//TODO Elham* this return the static to dynamic //TODO Elham* this return the static to dynamic
patientIdentificationID:"1062938285", //_idController.text, patientIdentificationID: "1062938285",
//_idController.text,
isHijri: 0, isHijri: 0,
isDentalAllowedBackend: false, isDentalAllowedBackend: false,
patientOutSA: 0, patientOutSA: 0,
generalid: GENERAL_ID, generalid: GENERAL_ID,
sessionID: null, sessionID: null,
dOB:"31/07/1988",//"${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "dd/MM/yyyy")}" dOB:
"31/07/1988", //"${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "dd/MM/yyyy")}"
); );
if (widget.model.state == ViewState.ErrorLocal) { if (widget.model.state == ViewState.ErrorLocal) {
Helpers.showErrorToast(widget.model.error); Helpers.showErrorToast(widget.model.error);
} else { } else {
await widget.model.getPatientInfo(getPatientInfoRequestModel); await widget.model
.getPatientInfo(getPatientInfoRequestModel);
if (widget.model.state == ViewState.ErrorLocal) { if (widget.model.state == ViewState.ErrorLocal) {
Helpers.showErrorToast(widget.model.error); Helpers.showErrorToast(widget.model.error);
} else { } else {
@ -318,7 +329,6 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
} }
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
} }
}, },
), ),
), ),
@ -329,49 +339,47 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
); );
} }
isFormValid() { isFormValid() {
if(_phoneController.text!=null &&_phoneController.text.isNotEmpty&& _idController.text!=null &&_idController.text.isNotEmpty &&_birthDate!=null) { if (_phoneController.text != null &&
_phoneController.text.isNotEmpty &&
_idController.text != null &&
_idController.text.isNotEmpty &&
_birthDateInGregorian != null) {
return true; return true;
} }
return false; return false;
} }
Future _selectDate(BuildContext context, DateTime dateTime, Future _selectDate(BuildContext context, DateTime dateTime,
Function(DateTime picked) updateDate) async { Function(dynamic) updateDate) async {
if(calenderType == CalenderType.Hijri) { if (calenderType == CalenderType.Hijri) {
final HijriCalendar picked = await showHijriDatePicker( HijriCalendar hijriDate = HijriCalendar.fromDate(DateTime.now());
final HijriCalendar pickedH = await showHijriDatePicker(
context: context, context: context,
initialDate: selectedHijriDate, initialDate: birthDateInHijri ?? hijriDate,
lastDate: new HijriCalendar() lastDate: new HijriCalendar()
..hYear = 1445 ..hYear = hijriDate.hYear
..hMonth = 9 ..hMonth = hijriDate.hMonth
..hDay = 25, ..hDay = hijriDate.hDay,
firstDate: new HijriCalendar() firstDate: new HijriCalendar()
..hYear = 1438 ..hYear = 1438
..hMonth = 12 ..hMonth = 12
..hDay = 25, ..hDay = 25,
initialDatePickerMode: DatePickerMode.day, initialDatePickerMode: DatePickerMode.day,
); );
if (picked != null && selectedHijriDate != picked) if (pickedH != null && birthDateInHijri != pickedH) updateDate(pickedH);
setState(() { } else {
selectedHijriDate = picked;
});
} else {
final DateTime picked = await showDatePicker( final DateTime picked = await showDatePicker(
context: context, context: context,
initialDate: dateTime, initialDate: dateTime ?? DateTime.now(),
firstDate: DateTime(DateTime.now().year - 150), firstDate: DateTime(DateTime.now().year - 150),
lastDate: DateTime(DateTime.now().year + 150), lastDate: DateTime.now(),
initialEntryMode: DatePickerEntryMode.calendar, initialEntryMode: DatePickerEntryMode.calendar,
); );
if (picked != null && picked != dateTime) { if (picked != null && picked != dateTime) {
updateDate(picked); updateDate(picked);
} }
} }
} }
void openListDialogField(String attributeName, String attributeValueId, void openListDialogField(String attributeName, String attributeValueId,
@ -394,4 +402,18 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
}, },
); );
} }
getBirthdate() {
if (calenderType == CalenderType.Hijri) {
return birthDateInHijri != null
? "$birthDateInHijri"
: null;
}else{
return _birthDateInGregorian != null
? "${AppDateUtils.convertStringToDateFormat(_birthDateInGregorian.toString(), "yyyy/MM/dd")}"
: null;
}
}
} }

@ -575,7 +575,7 @@ packages:
source: hosted source: hosted
version: "1.0.6" version: "1.0.6"
hijri: hijri:
dependency: "direct main" dependency: transitive
description: description:
name: hijri name: hijri
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

@ -104,7 +104,7 @@ dependencies:
badges: ^1.1.4 badges: ^1.1.4
# Hijri # Hijri
hijri: ^2.0.0 # hijri: ^2.0.3
hijri_picker: ^2.0.0 hijri_picker: ^2.0.0

Loading…
Cancel
Save