import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/InPatientServices/get_admitted_patient_response_model.dart'; import 'package:diplomaticquarterapp/models/InPatientServices/get_meal_items_schedule_response_model.dart'; import 'package:diplomaticquarterapp/models/InPatientServices/get_meals_schedule_response_model.dart'; import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:diplomaticquarterapp/widgets/avatar/large_avatar.dart'; import 'package:diplomaticquarterapp/widgets/my_rich_text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_expandable_notifier.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class MealPlanPage extends StatefulWidget { const MealPlanPage({Key key}) : super(key: key); @override State createState() => _MealPlanPageState(); } class _MealPlanPageState extends State { ProjectViewModel projectViewModel; GetAdmittedPatientsResponseModel getAdmittedPatientsResponseModel; List getMealsScheduleResponseModelList = []; List getMealItemsScheduleResponseModelBreakfast = []; List getMealItemsScheduleResponseModelLunch = []; List getMealItemsScheduleResponseModelDinner = []; List _getMealItemsScheduleResponseModelBreakfast = []; List _getMealItemsScheduleResponseModelLunch = []; List _getMealItemsScheduleResponseModelDinner = []; int currentDay = 0; int currentWeek = 0; @override void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) { getAdmittedPatientDetails(); }); } @override Widget build(BuildContext context) { projectViewModel = Provider.of(context); return AppScaffold( isShowAppBar: true, isShowDecPage: false, showNewAppBarTitle: true, showNewAppBar: true, appBarTitle: TranslationBase.of(context).mealPlanTitle, body: SingleChildScrollView( child: Padding( padding: EdgeInsets.all(21.0), child: Column( children: [ Container( decoration: containerRadius(getMealsScheduleResponseModelList[0].isShow ? Colors.white : Colors.grey[300], 12), child: AppExpandableNotifier( title: "Breakfast TAT: " + DateUtil.convertTime(getMealsScheduleResponseModelList[0].tATTime), isTitleSingleLine: false, widgetColor: Colors.transparent, isDisabled: !getMealsScheduleResponseModelList[0].isShow, bodyWidget: Column( children: [ getDivider(), ListView.separated( physics: BouncingScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { return Container( padding: EdgeInsets.all(21.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(_getMealItemsScheduleResponseModelBreakfast[index].filterName, style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18.0, letterSpacing: -0.64, color: CustomColors.darkGrey)), SizedBox( height: 12.0, ), ListView.separated( physics: NeverScrollableScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index2) { return Container( child: Row( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ LargeAvatar( name: _getMealItemsScheduleResponseModelBreakfast[index].getMealItemsScheduleResponseModelList[index2].description, url: "https://www.pumpkinnspice.com/wp-content/uploads/2016/03/easy-breakfast-quesadillas-11-683x1024.jpg", width: 60, height: 60, radius: 5, disableProfileView: true, ), SizedBox(width: 11), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ MyRichText( "", projectViewModel.isArabic ? _getMealItemsScheduleResponseModelBreakfast[index].getMealItemsScheduleResponseModelList[index2].descriptionN : _getMealItemsScheduleResponseModelBreakfast[index].getMealItemsScheduleResponseModelList[index2].description, projectViewModel.isArabic), ], ), ), ], ), ); }, separatorBuilder: (context, index) { return Padding( padding: EdgeInsets.all(16.0), child: Divider( height: 1.5, thickness: 1.0, color: Colors.grey.shade200, ), ); }, itemCount: _getMealItemsScheduleResponseModelBreakfast[index].getMealItemsScheduleResponseModelList.length), ], ), ); }, separatorBuilder: (context, index) { return Padding( padding: EdgeInsets.only(left: 15, right: 15), child: Divider( height: 1.5, thickness: 1.0, color: Colors.grey.shade200, ), ); }, itemCount: _getMealItemsScheduleResponseModelBreakfast.length), ], ), ), ), mHeight(21), Container( decoration: containerRadius(getMealsScheduleResponseModelList[1].isShow ? Colors.white : Colors.grey[300], 12), child: AppExpandableNotifier( title: "Lunch TAT: " + DateUtil.convertTime(getMealsScheduleResponseModelList[1].tATTime), isTitleSingleLine: false, widgetColor: Colors.transparent, isDisabled: !getMealsScheduleResponseModelList[1].isShow, bodyWidget: Column( children: [ getDivider(), ListView.separated( physics: BouncingScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { return Container( padding: EdgeInsets.all(21.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(_getMealItemsScheduleResponseModelLunch[index].filterName, style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18.0, letterSpacing: -0.64, color: CustomColors.darkGrey)), SizedBox( height: 12.0, ), ListView.separated( physics: NeverScrollableScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index2) { return Container( child: Row( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ LargeAvatar( name: _getMealItemsScheduleResponseModelLunch[index].getMealItemsScheduleResponseModelList[index2].description, url: "https://www.pumpkinnspice.com/wp-content/uploads/2016/03/easy-breakfast-quesadillas-11-683x1024.jpg", width: 60, height: 60, radius: 5, disableProfileView: true, ), SizedBox(width: 11), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ MyRichText( "", projectViewModel.isArabic ? _getMealItemsScheduleResponseModelLunch[index].getMealItemsScheduleResponseModelList[index2].descriptionN : _getMealItemsScheduleResponseModelLunch[index].getMealItemsScheduleResponseModelList[index2].description, projectViewModel.isArabic), ], ), ), ], ), ); }, separatorBuilder: (context, index) { return Padding( padding: EdgeInsets.all(16.0), child: Divider( height: 1.5, thickness: 1.0, color: Colors.grey.shade200, ), ); }, itemCount: _getMealItemsScheduleResponseModelLunch[index].getMealItemsScheduleResponseModelList.length), ], ), ); }, separatorBuilder: (context, index) { return Padding( padding: EdgeInsets.only(left: 15, right: 15), child: Divider( height: 1.5, thickness: 1.0, color: Colors.grey.shade200, ), ); }, itemCount: _getMealItemsScheduleResponseModelLunch.length), ], ), ), ), mHeight(21), Container( decoration: containerRadius(getMealsScheduleResponseModelList[2].isShow ? Colors.white : Colors.grey[300], 12), child: AppExpandableNotifier( title: "Dinner TAT: " + DateUtil.convertTime(getMealsScheduleResponseModelList[2].tATTime), isTitleSingleLine: false, widgetColor: Colors.transparent, isDisabled: !getMealsScheduleResponseModelList[2].isShow, bodyWidget: Column( children: [ getDivider(), ListView.separated( physics: BouncingScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { return Container( padding: EdgeInsets.all(21.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(_getMealItemsScheduleResponseModelDinner[index].filterName, style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18.0, letterSpacing: -0.64, color: CustomColors.darkGrey)), SizedBox( height: 12.0, ), ListView.separated( physics: NeverScrollableScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index2) { return Container( child: Row( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Radio( value: index, groupValue: _getMealItemsScheduleResponseModelDinner[index].filterName, activeColor: Colors.red[800], onChanged: (value) { // setState(() { // selected = value; // parameterCode = model.askDoctorReqTypes[index].parameterCode; // }); }, ), LargeAvatar( name: _getMealItemsScheduleResponseModelDinner[index].getMealItemsScheduleResponseModelList[index2].description, url: "https://www.pumpkinnspice.com/wp-content/uploads/2016/03/easy-breakfast-quesadillas-11-683x1024.jpg", width: 60, height: 60, radius: 5, disableProfileView: true, ), SizedBox(width: 11), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ MyRichText( "", projectViewModel.isArabic ? _getMealItemsScheduleResponseModelDinner[index].getMealItemsScheduleResponseModelList[index2].descriptionN : _getMealItemsScheduleResponseModelDinner[index].getMealItemsScheduleResponseModelList[index2].description, projectViewModel.isArabic), ], ), ), ], ), ); }, separatorBuilder: (context, index) { return Padding( padding: EdgeInsets.all(16.0), child: Divider( height: 1.5, thickness: 1.0, color: Colors.grey.shade200, ), ); }, itemCount: _getMealItemsScheduleResponseModelDinner[index].getMealItemsScheduleResponseModelList.length), ], ), ); }, separatorBuilder: (context, index) { return Padding( padding: EdgeInsets.only(left: 15, right: 15), child: Divider( height: 1.5, thickness: 1.0, color: Colors.grey.shade200, ), ); }, itemCount: _getMealItemsScheduleResponseModelDinner.length), ], ), ), ), ], ), ), ), ); } Widget getDivider() { return Padding( padding: EdgeInsets.only(left: 15, right: 15), child: Divider( height: 1.5, thickness: 2.0, color: Colors.black, ), ); } void getAdmittedPatientDetails() { ClinicListService service = new ClinicListService(); GifLoaderDialogUtils.showMyDialog(context); service.getAdmittedPatientDetails(projectViewModel.user.patientID, projectViewModel.inPatientProjectID, projectViewModel.getAdmissionInfoResponseModel.admissionNo, 0, 0, 0, context).then((res) { GifLoaderDialogUtils.hideDialog(context); if (res["List_MOP_AdmittedPatients"] != null && res["List_MOP_AdmittedPatients"].length != 0) { print(res["List_MOP_AdmittedPatients"]); getAdmittedPatientsResponseModel = new GetAdmittedPatientsResponseModel.fromJson(res["List_MOP_AdmittedPatients"][0]); print(getAdmittedPatientsResponseModel.dietType); getCurrentWeekIDAndDay(getAdmittedPatientsResponseModel.dietType); } else { AppToast.showErrorToast(message: "No data found for admitted patient"); getCurrentWeekIDAndDay(1); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); print(err); }); } void getCurrentWeekIDAndDay(int dietType) { ClinicListService service = new ClinicListService(); GifLoaderDialogUtils.showMyDialog(context); service.getCurrentWeekIDAndDay(context).then((res) { GifLoaderDialogUtils.hideDialog(context); currentDay = res["CurrentDay"]; currentWeek = res["CurrentWeek"]; getMealsOfScheduleID(dietType); }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); print(err); }); } void getMealsOfScheduleID(int dietType) { ClinicListService service = new ClinicListService(); GifLoaderDialogUtils.showMyDialog(context); service.getMealsOfScheduleID(projectViewModel.inPatientProjectID, projectViewModel.getAdmissionInfoResponseModel.admissionNo, dietType, currentWeek, currentDay, context).then((res) { GifLoaderDialogUtils.hideDialog(context); if (res["List_MOP_MealsOfScheduleID_Mobile"] != null && res["List_MOP_MealsOfScheduleID_Mobile"].length != 0) { res['List_MOP_MealsOfScheduleID_Mobile'].forEach((scheduleItem) { getMealsScheduleResponseModelList.add(GetMealsScheduleResponseModel.fromJson(scheduleItem)); }); if (getMealsScheduleResponseModelList[0].isShow) getDefaultItemsOfScheduleID(getMealsScheduleResponseModelList[0].scheduleID, 1); if (getMealsScheduleResponseModelList[1].isShow) getDefaultItemsOfScheduleID(getMealsScheduleResponseModelList[1].scheduleID, 2); if (getMealsScheduleResponseModelList[2].isShow) getDefaultItemsOfScheduleID(getMealsScheduleResponseModelList[2].scheduleID, 3); } else { AppToast.showErrorToast(message: "No meal schedule found for admitted patient"); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); print(err); }); } void getDefaultItemsOfScheduleID(int scheduleID, int mealType) { ClinicListService service = new ClinicListService(); GifLoaderDialogUtils.showMyDialog(context); service.getDefaultItemsOfScheduleID(projectViewModel.inPatientProjectID, scheduleID, context).then((res) { GifLoaderDialogUtils.hideDialog(context); if (res["List_MOP_DefaultItemsOfMealModel"] != null && res["List_MOP_DefaultItemsOfMealModel"].length != 0) { if (mealType == 1) { res['List_MOP_DefaultItemsOfMealModel'].forEach((scheduleItem) { getMealItemsScheduleResponseModelBreakfast.add(GetMealItemsScheduleResponseModel.fromJson(scheduleItem)); }); sortMealsByCategoryBreakfast(); } if (mealType == 2) { res['List_MOP_DefaultItemsOfMealModel'].forEach((scheduleItem) { getMealItemsScheduleResponseModelLunch.add(GetMealItemsScheduleResponseModel.fromJson(scheduleItem)); }); sortMealsByCategoryLunch(); } if (mealType == 3) { res['List_MOP_DefaultItemsOfMealModel'].forEach((scheduleItem) { getMealItemsScheduleResponseModelDinner.add(GetMealItemsScheduleResponseModel.fromJson(scheduleItem)); }); sortMealsByCategoryDinner(); } } else { AppToast.showErrorToast(message: "No meal items found for admitted patient"); } setState(() {}); }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); print(err); }); } void sortMealsByCategoryBreakfast() { getMealItemsScheduleResponseModelBreakfast.forEach((element) { List breakfastMealItems = _getMealItemsScheduleResponseModelBreakfast .where((elementClinic) => elementClinic.filterName == (projectViewModel.isArabic ? element.categoryDescriptionN : element.categoryDescription)) .toList(); if (breakfastMealItems.length != 0) { _getMealItemsScheduleResponseModelBreakfast[_getMealItemsScheduleResponseModelBreakfast.indexOf(breakfastMealItems[0])].getMealItemsScheduleResponseModelList.add(element); } else { _getMealItemsScheduleResponseModelBreakfast .add(GetMealItemsScheduleResponseModelList(filterName: projectViewModel.isArabic ? element.categoryDescriptionN : element.categoryDescription, getMealItemsScheduleResponseModel: element)); } }); } void sortMealsByCategoryLunch() { getMealItemsScheduleResponseModelLunch.forEach((element) { List breakfastMealItems = _getMealItemsScheduleResponseModelLunch .where((elementClinic) => elementClinic.filterName == (projectViewModel.isArabic ? element.categoryDescriptionN : element.categoryDescription)) .toList(); if (breakfastMealItems.length != 0) { _getMealItemsScheduleResponseModelLunch[_getMealItemsScheduleResponseModelLunch.indexOf(breakfastMealItems[0])].getMealItemsScheduleResponseModelList.add(element); } else { _getMealItemsScheduleResponseModelLunch .add(GetMealItemsScheduleResponseModelList(filterName: projectViewModel.isArabic ? element.categoryDescriptionN : element.categoryDescription, getMealItemsScheduleResponseModel: element)); } }); } void sortMealsByCategoryDinner() { getMealItemsScheduleResponseModelDinner.forEach((element) { List breakfastMealItems = _getMealItemsScheduleResponseModelDinner .where((elementClinic) => elementClinic.filterName == (projectViewModel.isArabic ? element.categoryDescriptionN : element.categoryDescription)) .toList(); if (breakfastMealItems.length != 0) { _getMealItemsScheduleResponseModelDinner[_getMealItemsScheduleResponseModelDinner.indexOf(breakfastMealItems[0])].getMealItemsScheduleResponseModelList.add(element); } else { _getMealItemsScheduleResponseModelDinner .add(GetMealItemsScheduleResponseModelList(filterName: projectViewModel.isArabic ? element.categoryDescriptionN : element.categoryDescription, getMealItemsScheduleResponseModel: element)); } }); } }