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 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();
}

@ -22,14 +22,14 @@ 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;
final PatientRegistrationViewModel model;
const RegisterSearchPatientPage({Key key, this.changePageViewIndex, this.model})
const RegisterSearchPatientPage(
{Key key, this.changePageViewIndex, this.model})
: super(key: key);
@override
@ -42,25 +42,25 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
dynamic _selectedCountry;
bool isSubmitted = false;
TextEditingController _phoneController = TextEditingController(text: "508079569");
TextEditingController _phoneController =
TextEditingController(text: "508079569");
TextEditingController _phoneCode = TextEditingController(text: "966");
String phoneError;
TextEditingController _idController = TextEditingController(text: "1062938285");
TextEditingController _idController =
TextEditingController(text: "1062938285");
String idError;
DateTime _birthDate;
DateTime _birthDateInGregorian;
String birthdateError;
var selectedHijriDate = new HijriCalendar.now();
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(
@ -112,14 +112,15 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
validationError: phoneError,
),
),
if(_phoneController
.text.isEmpty &&
isSubmitted
)
SizedBox(height: 35,)
if (_phoneController.text.isEmpty && isSubmitted)
SizedBox(
height: 35,
)
],
),
SizedBox(width: 10,),
SizedBox(
width: 10,
),
Expanded(
child: Container(
// width: MediaQuery.of(context).size.width*0.7,
@ -128,12 +129,10 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
hintText: "Phone Number",
inputType: TextInputType.phone,
controller: _phoneController,
validationError: _phoneController
.text.isEmpty &&
isSubmitted
? TranslationBase.of(context)
.emptyMessage
: null,
validationError:
_phoneController.text.isEmpty && isSubmitted
? TranslationBase.of(context).emptyMessage
: null,
),
),
),
@ -147,11 +146,8 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
hintText: "ID Number",
inputType: TextInputType.phone,
controller: _idController,
validationError: _idController
.text.isEmpty &&
isSubmitted
? TranslationBase.of(context)
.emptyMessage
validationError: _idController.text.isEmpty && isSubmitted
? TranslationBase.of(context).emptyMessage
: null,
),
SizedBox(
@ -199,15 +195,11 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
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
? TranslationBase.of(context)
.emptyMessage
validationError: _birthDateInGregorian == null && isSubmitted
? TranslationBase.of(context).emptyMessage
: null,
suffixIcon: IconButton(
icon: Icon(
@ -217,12 +209,29 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
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);
}
});
});
},
@ -274,42 +283,44 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
setState(() {
isSubmitted = true;
});
if(isFormValid()) {
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(_birthDate.toString(), "yyyy/MM/dd")}");
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(
GetPatientInfoRequestModel(
//TODO Elham* this return the static to dynamic
patientIdentificationID:"1062938285", //_idController.text,
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")}"
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);
await widget.model
.getPatientInfo(getPatientInfoRequestModel);
if (widget.model.state == ViewState.ErrorLocal) {
Helpers.showErrorToast(widget.model.error);
} else {
@ -318,7 +329,6 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
}
GifLoaderDialogUtils.hideDialog(context);
}
},
),
),
@ -329,49 +339,47 @@ class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
);
}
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 false;
}
Future _selectDate(BuildContext context, DateTime dateTime,
Function(DateTime picked) updateDate) async {
if(calenderType == CalenderType.Hijri) {
final HijriCalendar picked = await showHijriDatePicker(
Function(dynamic) updateDate) async {
if (calenderType == CalenderType.Hijri) {
HijriCalendar hijriDate = HijriCalendar.fromDate(DateTime.now());
final HijriCalendar pickedH = await showHijriDatePicker(
context: context,
initialDate: selectedHijriDate,
initialDate: birthDateInHijri ?? hijriDate,
lastDate: new HijriCalendar()
..hYear = 1445
..hMonth = 9
..hDay = 25,
..hYear = hijriDate.hYear
..hMonth = hijriDate.hMonth
..hDay = hijriDate.hDay,
firstDate: new HijriCalendar()
..hYear = 1438
..hMonth = 12
..hDay = 25,
initialDatePickerMode: DatePickerMode.day,
);
if (picked != null && selectedHijriDate != picked)
setState(() {
selectedHijriDate = picked;
});
} else {
if (pickedH != null && birthDateInHijri != pickedH) updateDate(pickedH);
} else {
final DateTime picked = await showDatePicker(
context: context,
initialDate: dateTime,
initialDate: dateTime ?? DateTime.now(),
firstDate: DateTime(DateTime.now().year - 150),
lastDate: DateTime(DateTime.now().year + 150),
lastDate: DateTime.now(),
initialEntryMode: DatePickerEntryMode.calendar,
);
if (picked != null && picked != dateTime) {
updateDate(picked);
}
}
}
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
version: "1.0.6"
hijri:
dependency: "direct main"
dependency: transitive
description:
name: hijri
url: "https://pub.dartlang.org"

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

Loading…
Cancel
Save