import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.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/viewModel/patient_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/sick_leave_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/sickleave/add_sickleave_request.dart'; import 'package:doctor_app_flutter/models/sickleave/get_all_sickleave_response.dart'; import 'package:doctor_app_flutter/routes.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/bottom_sheet_title.dart'; import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.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/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:intl/intl.dart'; Helpers helpers = Helpers(); class SickLeaveScreen extends StatefulWidget { final bool isExtended; final GetAllSickLeaveResponse extendedData; final appointmentNo; final patientMRN; final patient; SickLeaveScreen( {this.appointmentNo, this.patientMRN, this.isExtended = false, this.extendedData, this.patient}); @override _SickLeaveScreenState createState() => _SickLeaveScreenState(); } class _SickLeaveScreenState extends State { DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); TextEditingController _toDateController = new TextEditingController(); TextEditingController _numberOfDayController = new TextEditingController(); TextEditingController _clinicController = new TextEditingController(); TextEditingController _doctorController = new TextEditingController(); TextEditingController _remarkController = new TextEditingController(); Map profile = {}; AddSickLeaveRequest addSickLeave = AddSickLeaveRequest(); bool isFormSubmitted = false; void _presentDatePicker(id) { showDatePicker( context: context, initialDate: DateTime.now(), firstDate: DateTime(2019), lastDate: DateTime(2050), ).then((pickedDate) { if (pickedDate == null) { return; } setState(() { // var selectedDate = DateFormat.yMd().format(pickedDate); final df = new DateFormat('yyyy-MM-dd'); addSickLeave.startDate = df.format(pickedDate); _toDateController.text = addSickLeave.startDate; //addSickLeave.startDate = selectedDate; }); }); } @override void initState() { getProfile(); super.initState(); } @override Widget build(BuildContext context) { return BaseView( onModelReady: (model) async { await model.getClinicsList(); _clinicController.text = getClinicName(model); _doctorController.text = profile['DoctorName']; }, builder: (_, model, w) => BaseView( onModelReady: (model2) => model2.preSickLeaveStatistics( widget.appointmentNo, widget.patientMRN), builder: (_, model2, w) => GestureDetector( onTap: () { FocusScope.of(context).requestFocus(new FocusNode()); }, child: AppScaffold( baseViewModel: model2, appBar: BottomSheetTitle(title: widget.isExtended == true ? TranslationBase.of(context).extendSickLeave : TranslationBase.of(context).addSickLeave,), isShowAppBar: true, body: Center( child: Container( margin: EdgeInsets.only(top: 10), child: FractionallySizedBox( widthFactor: 0.9, child: ListView( children: [ SizedBox( height: 30, ), AppTextFieldCustom( height: Helpers.getTextFieldHeight(), hintText: widget.extendedData != null ? widget.extendedData.noOfDays.toString() : TranslationBase.of(context).sickLeave + ' ' + TranslationBase.of(context).days, maxLines: 1, minLines: 1, dropDownColor: Colors.white, isTextFieldHasSuffix: true, inputFormatters: [ FilteringTextInputFormatter.allow( RegExp(ONLY_NUMBERS)) ], controller: _numberOfDayController, onChanged: (value) { setState(() { addSickLeave.noOfDays = value; }); if (widget.extendedData != null) { widget.extendedData.noOfDays = int.parse(value); } }, validationError: isFormSubmitted && (addSickLeave.noOfDays == null) ? TranslationBase.of(context) .pleaseEnterNoOfDays : null, ), SizedBox( height: 10, ), AppTextFieldCustom( height: Helpers.getTextFieldHeight(), onClick: () { _presentDatePicker('_selectedToDate'); }, hintText: widget.extendedData != null ? widget.extendedData.startDate : TranslationBase.of(context) .sickLeaveDate, enabled: false, maxLines: 1, minLines: 1, isTextFieldHasSuffix: true, suffixIcon: IconButton( icon: Icon(Icons.calendar_today)), inputFormatters: [ FilteringTextInputFormatter.allow( RegExp(ONLY_NUMBERS)) ], controller: _toDateController, onChanged: (value) { setState(() { addSickLeave.startDate = value; }); if (widget.extendedData != null) { widget.extendedData.startDate = value; } }, validationError: isFormSubmitted && (addSickLeave.startDate == null) ? TranslationBase.of(context) .pleaseEnterDate : null, ), SizedBox( height: 5, ), AppTextFieldCustom( height: Helpers.getTextFieldHeight(), hintText: TranslationBase.of(context).clinic, enabled: false, maxLines: 1, minLines: 1, dropDownColor: Colors.white, isTextFieldHasSuffix: true, inputFormatters: [ FilteringTextInputFormatter.allow( RegExp(ONLY_NUMBERS)) ], controller: _clinicController, onChanged: (value) {}, ), SizedBox( height: 10, ), model2.sickLeaveStatistics[ 'recommendedSickLeaveDays'] != null ? Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( width: 10, ), Icon( DoctorApp.warning, size: 20, color: IN_PROGRESS_COLOR, ), SizedBox( width: 10, ), AppText( model2.sickLeaveStatistics[ 'recommendedSickLeaveDays'], textAlign: TextAlign.start, fontSize: 12, color: IN_PROGRESS_COLOR, ), ], ) : SizedBox( height: 10, ), SizedBox( height: 10, ), AppTextFieldCustom( height: Helpers.getTextFieldHeight(), hintText: TranslationBase.of(context).doctor, enabled: false, maxLines: 1, minLines: 1, dropDownColor: Colors.white, isTextFieldHasSuffix: true, inputFormatters: [ FilteringTextInputFormatter.allow( RegExp(ONLY_NUMBERS)) ], controller: _doctorController, onChanged: (value) {}, ), SizedBox( height: 10, ), AppTextFieldCustom( height: Helpers.getTextFieldHeight(), hintText: widget.extendedData != null ? widget.extendedData.remarks : TranslationBase.of(context).remarks, maxLines: 30, minLines: 5, dropDownColor: Colors.white, isTextFieldHasSuffix: true, controller: _remarkController, onChanged: (value) { setState(() { addSickLeave.remarks = value; }); if (widget.extendedData != null) { widget.extendedData.remarks = value; } }, validationError: isFormSubmitted && (addSickLeave.remarks == null) ? TranslationBase.of(context) .pleaseEnterRemarks : null, ), ], ), ), ), ), bottomSheet: model2.state == ViewState.Busy || model.state == ViewState.Busy ? Container( height: 0, ) : Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(0.0), ), border: Border.all( color: HexColor('#707070'), width: 0), ), height: SizeConfig.heightMultiplier * (SizeConfig.isHeightVeryShort ? 12 : 10), width: double.infinity, child: Column( children: [ SizedBox( height: 10, ), FractionallySizedBox( widthFactor: 0.9, child: AppButton( title: widget.isExtended == true ? TranslationBase.of(context).extend : TranslationBase.of(context) .addSickLeaverequest, color: Colors.green, onPressed: () async { submitForm(model2); }), ), SizedBox( height: 5, ), ], ), )), ))); } submitForm(SickLeaveViewModel model2) async { { if (widget.isExtended) { GifLoaderDialogUtils.showMyDialog(context); await model2.extendSickLeave(widget.extendedData); if (model2.state == ViewState.ErrorLocal) { Helpers.showErrorToast(model2.error); } else { DrAppToastMsg.showSuccesToast( TranslationBase.of(context).replySuccessfully); Navigator.of(context).popUntil((route) { return route.settings.name == PATIENTS_PROFILE; }); Navigator.of(context) .pushNamed(ADD_SICKLEAVE, arguments: {'patient': widget.patient}); } GifLoaderDialogUtils.hideDialog(context); } else { try { setState(() { isFormSubmitted = true; }); if (addSickLeave.noOfDays == null || addSickLeave.startDate == null || addSickLeave.remarks == null) { return; } else { GifLoaderDialogUtils.showMyDialog(context); addSickLeave.patientMRN = widget.patient.patientMRN.toString(); addSickLeave.appointmentNo = widget.patient.appointmentNo.toString(); await model2.addSickLeave(addSickLeave); if (model2.state == ViewState.ErrorLocal) { Helpers.showErrorToast(model2.error); } else { DrAppToastMsg.showSuccesToast( TranslationBase.of(context).replySuccessfully); } GifLoaderDialogUtils.hideDialog(context); } } catch (err) { print(err); } } } } getProfile() async { Map p = await sharedPref.getObj(DOCTOR_PROFILE); setState(() { this.profile = p; }); } getClinicName(model) { var clinicInfo = model.clinicsList .where((i) => i['ClinicID'] == this.profile['ClinicID']) .toList(); return clinicInfo.length > 0 ? clinicInfo[0]['ClinicDescription'] : ""; } }