WD: Date from and date to added to the dialog and limit handled

update_3.16.0_CR5439_Pharmacy_Intervention
taha.alam 1 year ago
parent 9fa4fc445c
commit 2ec7672b29

@ -581,8 +581,10 @@ class PharmacyInterventionViewModel extends BaseViewModel {
DrAppToastMsg.showErrorToast(errorMessage); DrAppToastMsg.showErrorToast(errorMessage);
return; return;
} }
DrAppToastMsg.showSuccesToast(successMessage); if(result) {
getPharmacyIntervention(); DrAppToastMsg.showSuccesToast(successMessage);
getPharmacyIntervention();
}
setState(ViewState.Idle); setState(ViewState.Idle);
} }

@ -53,8 +53,8 @@ class _PharmacyInterventionDialogState
admissionNumber.text = (widget.admissionNumber == '0')?'':widget.admissionNumber; admissionNumber.text = (widget.admissionNumber == '0')?'':widget.admissionNumber;
nursingStation.text = (widget.nursingStation == '0')?'':widget.nursingStation; nursingStation.text = (widget.nursingStation == '0')?'':widget.nursingStation;
patientId.text = (widget.patientID == '0' )?'':widget.patientID; patientId.text = (widget.patientID == '0' )?'':widget.patientID;
dateTo = getDate(widget.dateTo); dateTo = getDateString(widget.dateTo);
dateFrom = getDate(widget.dateFrom); dateFrom = getDateString(widget.dateFrom);
} }
@override @override
@ -102,10 +102,25 @@ class _PharmacyInterventionDialogState
_dateSelection(TranslationBase _dateSelection(TranslationBase
.of(context) .of(context)
.dateFrom, (date) { .dateFrom, (date) {
DateTime? fromDate = getDate(date);
DateTime? toDate =getDate(dateTo);
if(toDate == null){
setState(() {
dateFrom = date;
});
return;
}
if(fromDate!.compareTo(toDate!) == 1){
setState(() {
dateFrom = date;
dateTo = '';
});
return;
}
setState(() { setState(() {
dateFrom = date; dateFrom = date;
}); });
}, dateFrom), }, dateFrom, false),
SizedBox( SizedBox(
height: 4, height: 4,
), ),
@ -115,7 +130,7 @@ class _PharmacyInterventionDialogState
setState(() { setState(() {
dateTo = date; dateTo = date;
}); });
}, dateTo), }, dateTo, true, selectedFromDate: dateFrom),
SizedBox( SizedBox(
height: 8, height: 8,
), ),
@ -144,9 +159,9 @@ class _PharmacyInterventionDialogState
} }
Widget _dateSelection(String title, Function(String) onDateSelected, Widget _dateSelection(String title, Function(String) onDateSelected,
String selectedDate) { String selectedDate, bool isToDateSelection,{String? selectedFromDate}) {
return GestureDetector( return GestureDetector(
onTap: () => _selectDate(onDateSelected), onTap: () => _selectDate(onDateSelected,selectedDate, isToDateSelection , selectedFromDate: selectedFromDate),
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@ -164,11 +179,13 @@ class _PharmacyInterventionDialogState
); );
} }
Future _selectDate(Function(String) updateDate) async { Future _selectDate(Function(String) updateDate , String date, bool toDateSelection, {String? selectedFromDate}) async {
DateTime? dateTime = getDate(date);
DateTime? fromDate = getDate(selectedFromDate??'');
final DateTime? picked = await showDatePicker( final DateTime? picked = await showDatePicker(
context: context, context: context,
initialDate: DateTime.now(), initialDate:date.isNotEmpty? getDate(date) :fromDate != null? fromDate: DateTime.now(),
firstDate: DateTime(DateTime firstDate:(( date.isNotEmpty && dateTime != null ) ) ? dateTime: (toDateSelection && fromDate != null)?fromDate :DateTime(DateTime
.now() .now()
.year - 150), .year - 150),
lastDate: DateTime(DateTime lastDate: DateTime(DateTime
@ -226,11 +243,18 @@ class _PharmacyInterventionDialogState
return DateFormat('yyyy-MM-dd').format(time); return DateFormat('yyyy-MM-dd').format(time);
} }
String getDate(String dateTime) { String getDateString(String dateTime) {
if (dateTime.isEmpty) return ''; if (dateTime.isEmpty) return '';
DateTime? now = getDate(dateTime);
if(now == null ) return '';
return DateFormat('yyyy-MM-dd').format(now);
}
DateTime? getDate(String dateTime){
if (dateTime.isEmpty) return null;
List<String> splitedDate = dateTime.split('-'); List<String> splitedDate = dateTime.split('-');
DateTime now = DateTime(int.parse(splitedDate[0]), DateTime now = DateTime(int.parse(splitedDate[0]),
int.parse(splitedDate[1]), int.parse(splitedDate[2])); int.parse(splitedDate[1]), int.parse(splitedDate[2]));
return DateFormat('yyyy-MM-dd').format(now); return now;
} }
} }
Loading…
Cancel
Save