diff --git a/lib/controllers/providers/api/service_requests_provider.dart b/lib/controllers/providers/api/service_requests_provider.dart index 925f7cc9..4f6096c1 100644 --- a/lib/controllers/providers/api/service_requests_provider.dart +++ b/lib/controllers/providers/api/service_requests_provider.dart @@ -62,7 +62,6 @@ class ServiceRequestsProvider extends ChangeNotifier { List _sparePartList = []; SparePartsWorkOrders _initialSelectedSparePart = SparePartsWorkOrders(); - ServiceRequest? _currentSelectedRequest; int _selectedListIndex = 0; int get selectedListIndex => _selectedListIndex; @@ -72,10 +71,10 @@ class ServiceRequestsProvider extends ChangeNotifier { notifyListeners(); } - ServiceRequest? get currentSelectedRequest => _currentSelectedRequest; + ServiceRequest? currentSelectedRequest; - set currentSelectedRequest(ServiceRequest? value) { - _currentSelectedRequest = value; + void updateCurrentSelectedRequest(ServiceRequest? value) { + currentSelectedRequest = value; notifyListeners(); } @@ -326,10 +325,10 @@ class ServiceRequestsProvider extends ChangeNotifier { "status": request.statusId == null ? null : { - "id": request.statusId, - "name": request.statusLabel, - "value": request.statusValue, - }, + "id": request.statusId, + "name": request.statusLabel, + "value": request.statusValue, + }, "callLastSituation": null, "firstAction": request.firstAction?.toJson(), "loanAvailablity": request.loanAvailability?.toJson(), @@ -614,18 +613,18 @@ class ServiceRequestsProvider extends ChangeNotifier { Future getServiceRequestObjectById({required String requestId}) async { // try { - isDetialLoading = true; - Response response = await ApiManager.instance.get(URLs.getServiceRequestById + "?callRequestId=$requestId"); - if (response.statusCode >= 200 && response.statusCode < 300) { - isDetialLoading = false; - return ServiceRequest.fromJson(json.decode(response.body)["data"]); - } else { - isDetialLoading = false; - return null; - } - // } catch (error) { + isDetialLoading = true; + Response response = await ApiManager.instance.get(URLs.getServiceRequestById + "?callRequestId=$requestId"); + if (response.statusCode >= 200 && response.statusCode < 300) { + isDetialLoading = false; + return ServiceRequest.fromJson(json.decode(response.body)["data"]); + } else { isDetialLoading = false; return null; + } + // } catch (error) { + isDetialLoading = false; + return null; // } } @@ -653,11 +652,11 @@ class ServiceRequestsProvider extends ChangeNotifier { } Future> searchForWorkOrders( - SearchWorkOrder search, - String callerId, - Lookup dateOperator, - String site, - ) async { + SearchWorkOrder search, + String callerId, + Lookup dateOperator, + String site, + ) async { Response response; try { var body = { diff --git a/lib/models/service_request/service_request.dart b/lib/models/service_request/service_request.dart index 31f259a2..28dc666b 100644 --- a/lib/models/service_request/service_request.dart +++ b/lib/models/service_request/service_request.dart @@ -180,6 +180,34 @@ class ServiceRequest { } return true; } + Map toFixRemotelyJson() { + return {'workOrderId': id, 'startDate': startDate, 'endDate': endDate, 'workingHour': workingHours, 'comment': comments}; + } + //TODO feedback not defined... + Map toMarkAsFixedJson() { + return {'workOrderId': id, 'feedback': comments}; + } + Map toNeedVisitJson() { + return {'workOrderId': id, 'visitDate': visitDate, 'comment': comments}; + } + //TODO signatureNurse not defined... + Map toNurseActionJson() { + return {'workOrderId': id, 'feedback': comments, 'signatureNurse': 'signatureNurse'}; + } + //TODO workOrder fields not defined... + Map toWorkOrderJson() { + final Map data = {}; + data['workOrderId'] = id; + data['equipmentStatusId'] = statusValue; + data['returnToService'] = 're'; + data['serviceTypeId'] = 'se'; + data['loanAvailabilityId'] = loanAvailability; + data['loanAssetId'] = loanAvailability?.id; + data['failureReasonId'] = faultDescription?.id; + data['faultDescriptionId'] = 'faultDescriptionId'; + data['solution'] = 'solution'; + return data; + } } class CallCreatedBy { diff --git a/lib/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart b/lib/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart index e15a7df0..683b6b19 100644 --- a/lib/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart +++ b/lib/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart @@ -29,150 +29,413 @@ import '../../../../new_views/common_widgets/app_filled_button.dart'; import '../../../../new_views/common_widgets/app_text_form_field.dart'; class ServiceRequestBottomSheet { - static Future fixRemotelyBottomSheet({required BuildContext context}) { - final GlobalKey _formKey = GlobalKey(); + static buildBottomSheetParentWithConsumer({required BuildContext context, required Widget childWidget}) { return showModalBottomSheet( + context: context, + useSafeArea: true, + isScrollControlled: true, + backgroundColor: Colors.transparent, + builder: (context) => SingleChildScrollView( + child: childWidget, + ).bottomSheetContainer(context), + ); + } + + static Future fixRemotelyBottomSheet({required BuildContext context}) { + return buildBottomSheetParentWithConsumer( context: context, - useSafeArea: true, - isScrollControlled: true, - backgroundColor: Colors.transparent, - builder: (context) => Consumer(builder: (context, serviceRequestProvider, child) { - return Container( - clipBehavior: Clip.antiAlias, - margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), - decoration: BoxDecoration( - color: AppColor.background(context), - borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), - ), - padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), - child: Form( - key: _formKey, - child: SingleChildScrollView( - child: StatefulBuilder(builder: (context, setState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const SizedBox().indicatorWidget(), - 16.height, - Align( - alignment: AlignmentDirectional.centerStart, - child: context.translation.fillDetails.bottomSheetHeadingTextStyle(context), - ), - 16.height, - ADatePicker( - label: context.translation.date, - hideShadow: true, - // height: 60.toScreenHeight, - backgroundColor: AppColor.neutral100, - date: DateTime.tryParse(serviceRequestProvider.currentSelectedRequest?.startDate ?? ""), - formatDateWithTime: true, - onDatePicker: (selectedDate) { - if (selectedDate != null) { - showTimePicker( - context: context, - initialTime: TimeOfDay.now(), - ).then((selectedTime) { - // Handle the selected date and time here. - if (selectedTime != null) { - DateTime selectedDateTime = DateTime( - selectedDate.year, - selectedDate.month, - selectedDate.day, - selectedTime.hour, - selectedTime.minute, - ); - //serviceRequestProvider.currentSelectedRequest?.date - if (selectedDateTime.isBefore(DateTime.parse(serviceRequestProvider.currentSelectedRequest!.date!))) { - "Visit Date time must be greater then request date".showToast; - return; - } + childWidget: Consumer(builder: (context, serviceRequestProvider, child) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox().indicatorWidget(), + 16.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.fillDetails.bottomSheetHeadingTextStyle(context), + ), + 16.height, + ADatePicker( + label: context.translation.date, + hideShadow: true, + // height: 60.toScreenHeight, + backgroundColor: AppColor.neutral100, + date: DateTime.tryParse(serviceRequestProvider.currentSelectedRequest?.startDate ?? ""), + formatDateWithTime: true, + onDatePicker: (selectedDate) { + if (selectedDate != null) { + showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ).then((selectedTime) { + // Handle the selected date and time here. + if (selectedTime != null) { + DateTime selectedDateTime = DateTime( + selectedDate.year, + selectedDate.month, + selectedDate.day, + selectedTime.hour, + selectedTime.minute, + ); + //serviceRequestProvider.currentSelectedRequest?.date + if (selectedDateTime.isBefore(DateTime.parse(serviceRequestProvider.currentSelectedRequest!.date!))) { + "Visit Date time must be greater then request date".showToast; + return; + } + serviceRequestProvider.currentSelectedRequest?.startDate = selectedDateTime.toIso8601String(); + serviceRequestProvider.updateCurrentSelectedRequest(serviceRequestProvider.currentSelectedRequest); - setState(() { - serviceRequestProvider.currentSelectedRequest?.startDate = selectedDateTime.toIso8601String(); - }); - print('start date i got is ${serviceRequestProvider.currentSelectedRequest?.startDate}'); - } - }); - } - }, - ), - 8.height, - SizedBox( - width: double.infinity, - height: 56.toScreenHeight, - // padding: EdgeInsets.symmetric(horizontal: 20.toScreenWidth, vertical: 10.toScreenHeight), - child: AppTimer( - label: context.translation.workingHours, - timer: TimerModel(), - decoration: BoxDecoration( - color: context.isDark ? AppColor.neutral20 : AppColor.neutral100, - borderRadius: BorderRadius.circular(10), - // boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)], - ), - // enabled: serviceRequestProvider.currentSelectedRequest.date == null, - enabled: true, - onChange: (timer) async { - print('timer i got is ${timer.toString()}'); - return true; - }, - ), - ), - 8.height, - AppTextFormField( - labelText: context.translation.comments, - textInputType: TextInputType.multiline, - labelStyle: AppTextStyles.textFieldLabelStyle, - showWithoutDecoration: true, - backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, - alignLabelWithHint: true, - onChange: (text) { - serviceRequestProvider.currentSelectedRequest?.comments = text; - }, - onSaved: (text) { - serviceRequestProvider.currentSelectedRequest?.comments = text; - }, - ), - 16.height, - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SizedBox( - width: 200.toScreenHeight, - child: AppFilledButton( - label: context.translation.cancel, - loading: false, - buttonColor: Colors.transparent, - showBorder: true, - textColor: AppColor.black20, - onPressed: () async { - Navigator.pop(context); - // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.serviceRequest); - // Navigator.pop(context, true); - }, - ), - ), - SizedBox( - width: 200.toScreenHeight, - child: AppFilledButton( - label: context.translation.fixed, - buttonColor: AppColor.green70, - loading: false, - onPressed: () {}, - ), - ), - ], - ), - 16.height, - ], - ); - }), + } + }); + } + }, + ), + 8.height, + SizedBox( + width: double.infinity, + height: 56.toScreenHeight, + // padding: EdgeInsets.symmetric(horizontal: 20.toScreenWidth, vertical: 10.toScreenHeight), + child: AppTimer( + label: context.translation.workingHours, + timer: TimerModel(), + decoration: BoxDecoration( + color: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + borderRadius: BorderRadius.circular(10), + // boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)], ), + // enabled: serviceRequestProvider.currentSelectedRequest.date == null, + enabled: true, + onChange: (timer) async { + print('timer i got is ${timer.toString()}'); + return true; + }, ), - ); - })); + ), + 8.height, + AppTextFormField( + labelText: context.translation.comments, + textInputType: TextInputType.multiline, + labelStyle: AppTextStyles.textFieldLabelStyle, + showWithoutDecoration: true, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + alignLabelWithHint: true, + onChange: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + onSaved: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + ), + 16.height, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + width: 200.toScreenHeight, + child: AppFilledButton( + label: context.translation.cancel, + loading: false, + buttonColor: Colors.transparent, + showBorder: true, + textColor: AppColor.black20, + onPressed: () async { + Navigator.pop(context); + // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.serviceRequest); + // Navigator.pop(context, true); + }, + ), + ), + SizedBox( + width: 200.toScreenHeight, + child: AppFilledButton( + label: context.translation.fixed, + buttonColor: AppColor.green70, + loading: false, + onPressed: () {}, + ), + ), + ], + ), + 16.height, + ], + ); + })); + // showModalBottomSheet( + // context: context, + // useSafeArea: true, + // isScrollControlled: true, + // backgroundColor: Colors.transparent, + // builder: (context) => Consumer(builder: (context, serviceRequestProvider, child) { + // return Form( + // key: _formKey, + // child: SingleChildScrollView( + // child: StatefulBuilder(builder: (context, setState) { + // return Column( + // crossAxisAlignment: CrossAxisAlignment.center, + // children: [ + // const SizedBox().indicatorWidget(), + // 16.height, + // Align( + // alignment: AlignmentDirectional.centerStart, + // child: context.translation.fillDetails.bottomSheetHeadingTextStyle(context), + // ), + // 16.height, + // ADatePicker( + // label: context.translation.date, + // hideShadow: true, + // // height: 60.toScreenHeight, + // backgroundColor: AppColor.neutral100, + // date: DateTime.tryParse(serviceRequestProvider.currentSelectedRequest?.startDate ?? ""), + // formatDateWithTime: true, + // onDatePicker: (selectedDate) { + // if (selectedDate != null) { + // showTimePicker( + // context: context, + // initialTime: TimeOfDay.now(), + // ).then((selectedTime) { + // // Handle the selected date and time here. + // if (selectedTime != null) { + // DateTime selectedDateTime = DateTime( + // selectedDate.year, + // selectedDate.month, + // selectedDate.day, + // selectedTime.hour, + // selectedTime.minute, + // ); + // //serviceRequestProvider.currentSelectedRequest?.date + // if (selectedDateTime.isBefore(DateTime.parse(serviceRequestProvider.currentSelectedRequest!.date!))) { + // "Visit Date time must be greater then request date".showToast; + // return; + // } + // + // setState(() { + // serviceRequestProvider.currentSelectedRequest?.startDate = selectedDateTime.toIso8601String(); + // }); + // print('start date i got is ${serviceRequestProvider.currentSelectedRequest?.startDate}'); + // } + // }); + // } + // }, + // ), + // 8.height, + // SizedBox( + // width: double.infinity, + // height: 56.toScreenHeight, + // // padding: EdgeInsets.symmetric(horizontal: 20.toScreenWidth, vertical: 10.toScreenHeight), + // child: AppTimer( + // label: context.translation.workingHours, + // timer: TimerModel(), + // decoration: BoxDecoration( + // color: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + // borderRadius: BorderRadius.circular(10), + // // boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)], + // ), + // // enabled: serviceRequestProvider.currentSelectedRequest.date == null, + // enabled: true, + // onChange: (timer) async { + // print('timer i got is ${timer.toString()}'); + // return true; + // }, + // ), + // ), + // 8.height, + // AppTextFormField( + // labelText: context.translation.comments, + // textInputType: TextInputType.multiline, + // labelStyle: AppTextStyles.textFieldLabelStyle, + // showWithoutDecoration: true, + // backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + // alignLabelWithHint: true, + // onChange: (text) { + // serviceRequestProvider.currentSelectedRequest?.comments = text; + // }, + // onSaved: (text) { + // serviceRequestProvider.currentSelectedRequest?.comments = text; + // }, + // ), + // 16.height, + // Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + // children: [ + // SizedBox( + // width: 200.toScreenHeight, + // child: AppFilledButton( + // label: context.translation.cancel, + // loading: false, + // buttonColor: Colors.transparent, + // showBorder: true, + // textColor: AppColor.black20, + // onPressed: () async { + // Navigator.pop(context); + // // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.serviceRequest); + // // Navigator.pop(context, true); + // }, + // ), + // ), + // SizedBox( + // width: 200.toScreenHeight, + // child: AppFilledButton( + // label: context.translation.fixed, + // buttonColor: AppColor.green70, + // loading: false, + // onPressed: () {}, + // ), + // ), + // ], + // ), + // 16.height, + // ], + // ); + // }), + // ), + // ).bottomSheetContainer(context); + // })); } static Future initialVisitBottomSheet({required BuildContext context}) { + + return buildBottomSheetParentWithConsumer( + context: context, + childWidget: Consumer(builder: (context, serviceRequestProvider, child) { + return Column( + children: [ + const SizedBox().indicatorWidget(), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.setVisitDate.bottomSheetHeadingTextStyle(context), + ), + 15.height, + ADatePicker( + label: context.translation.visitDate, + hideShadow: true, + backgroundColor: AppColor.neutral100, + date: DateTime.tryParse(serviceRequestProvider.currentSelectedRequest?.visitDate ?? ""), + formatDateWithTime: true, + onDatePicker: (selectedDate) { + if (selectedDate != null) { + showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ).then((selectedTime) { + // Handle the selected date and time here. + if (selectedTime != null) { + DateTime selectedDateTime = DateTime( + selectedDate.year, + selectedDate.month, + selectedDate.day, + selectedTime.hour, + selectedTime.minute, + ); + if (selectedDateTime.isBefore(DateTime.parse(serviceRequestProvider.currentSelectedRequest!.date!))) { + "Visit Date time must be greater then request date".showToast; + return; + } + serviceRequestProvider.currentSelectedRequest?.visitDate = selectedDateTime?.toIso8601String(); + serviceRequestProvider.updateCurrentSelectedRequest(serviceRequestProvider.currentSelectedRequest); + } + }); + } + }, + ), + if (serviceRequestProvider.currentSelectedRequest?.firstAction?.id == 404 && Provider.of(context, listen: false).assetGroup?.id == 1) ...[ + 8.height, + Row( + children: [ + ADatePicker( + label: context.translation.startDate, + date: DateTime.tryParse(serviceRequestProvider.currentSelectedRequest?.startDate ?? ""), + formatDateWithTime: true, + onDatePicker: (selectedDate) { + if (selectedDate != null) { + showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ).then((selectedTime) { + // Handle the selected date and time here. + if (selectedTime != null) { + DateTime selectedDateTime = DateTime( + selectedDate.year, + selectedDate.month, + selectedDate.day, + selectedTime.hour, + selectedTime.minute, + ); + if (selectedDateTime != null) { + serviceRequestProvider.currentSelectedRequest?.startDate = selectedDateTime?.toIso8601String(); + } + } + }); + } + }, + ).expanded, + 8.width, + ADatePicker( + label: context.translation.endDate, + date: DateTime.tryParse(serviceRequestProvider.currentSelectedRequest?.endDate ?? ""), + formatDateWithTime: true, + onDatePicker: (selectedDate) { + showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ).then((selectedTime) { + // Handle the selected date and time here. + if (selectedTime != null) { + DateTime selectedDateTime = DateTime( + selectedDate.year, + selectedDate.month, + selectedDate.day, + selectedTime.hour, + selectedTime.minute, + ); + serviceRequestProvider.currentSelectedRequest?.endDate = selectedDateTime?.toIso8601String(); + serviceRequestProvider.currentSelectedRequest?.workingHours = (((DateTime.parse(serviceRequestProvider.currentSelectedRequest!.endDate!) + .difference(DateTime.parse(serviceRequestProvider.currentSelectedRequest!.startDate!)) + .inSeconds ?? + 0) / + 60) / + 60) + .toStringAsFixed(2); + } + }); + }, + ).expanded, + ], + ) + ], + 8.height, + AppTextFormField( + labelText: context.translation.comments, + backgroundColor: AppColor.neutral100, + labelStyle: AppTextStyles.textFieldLabelStyle, + showShadow: false, + textInputType: TextInputType.multiline, + alignLabelWithHint: true, + onChange: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + onSaved: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + ), + 12.height, + AppFilledButton( + label: context.translation.save, + buttonColor: AppColor.primary10, + loading: serviceRequestProvider.isLoading ?? false, + onPressed: () async { + // formKey.currentState?.save(); + + // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.serviceRequest); + // Navigator.pop(context, true); + Navigator.of(context).push(MaterialPageRoute(builder: (_) => VerifyArrivalView())); + }, + ), + 16.height, + ], + ); + })); + final GlobalKey _formKey = GlobalKey(); return showModalBottomSheet( context: context, @@ -281,9 +544,9 @@ class ServiceRequestBottomSheet { 60) / 60) .toStringAsFixed(2); - } + } }); - }, + }, ).expanded, ], ) @@ -325,6 +588,68 @@ class ServiceRequestBottomSheet { } static Future rejectRequestBottomSheet({required BuildContext context}) { + return buildBottomSheetParentWithConsumer( + context: context, + childWidget: Consumer(builder: (context, serviceRequestProvider, child) { + return Column( + children: [ + const SizedBox().indicatorWidget(), + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.rejectionReason.heading4(context).paddingOnly(top: 21), + ), + 15.height, + SingleItemDropDownMenu( + context: context, + backgroundColor: AppColor.neutral100, + height: 56.toScreenHeight, + title: context.translation.reason, + initialValue: serviceRequestProvider.currentSelectedRequest?.firstAction, + //_serviceRequest.firstAction, + onSelect: (value) { + serviceRequestProvider.currentSelectedRequest?.firstAction = value; + if (serviceRequestProvider.currentSelectedRequest?.firstAction?.value != 2) { + serviceRequestProvider.currentSelectedRequest?.visitDate = null; + } + }, + ), + 12.height, + AppTextFormField( + backgroundColor: AppColor.neutral100, + labelText: context.translation.comments, + textInputType: TextInputType.multiline, + alignLabelWithHint: true, + labelStyle: AppTextStyles.textFieldLabelStyle, + onChange: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + onSaved: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + ), + 16.height, + Consumer( + builder: (context, snapshot, _) => AppFilledButton( + label: context.translation.reject, + maxWidth: true, + buttonColor: Colors.white54, + textColor: AppColor.red30, + showBorder: true, + loading: snapshot.isLoading ?? false, + onPressed: () async { + + //Todo implement backend logic.. + // serviceRequestProvider.serviceRequest.device = asset; + // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.currentSelectedRequest); + Navigator.pop(context, true); + }, + ), + ), + 16.height, + ], + ); + })); + final GlobalKey _formKey = GlobalKey(); return showModalBottomSheet( context: context, @@ -381,7 +706,7 @@ class ServiceRequestBottomSheet { showBorder: true, loading: snapshot.isLoading ?? false, onPressed: () async { - _formKey.currentState?.save(); + //Todo implement backend logic.. // serviceRequestProvider.serviceRequest.device = asset; // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.currentSelectedRequest); @@ -441,23 +766,41 @@ class ServiceRequestBottomSheet { // MaterialPageRoute(builder: (context) => ActivitiesListView()), // ); break; - case 2: - //push to specific screen... - // Navigator.push( - // context, - // MaterialPageRoute(builder: (context) => const ScanQrView()), - // ); - break; - case 2: - //push to specific screen... - // Navigator.push( - // context, - // MaterialPageRoute(builder: (context) => const ScanQrView()), - // ); - break; } - // ScanQr } + return buildBottomSheetParentWithConsumer( + context: context, + childWidget: Consumer(builder: (context, serviceRequestProvider, child) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox().indicatorWidget(), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.selectActivityType.bottomSheetHeadingTextStyle(context), + ), + 16.height, + ListView.builder( + shrinkWrap: true, + padding: EdgeInsets.zero, + itemCount: items.length, + itemBuilder: (context, index) { + final item = items[index]; + return listItem( + icon: item['icon']!, + heading: item['heading']!, + subHeading: item['subHeading']!, + context: context, + onTap: () { + onItemTap(serviceRequest: serviceRequestProvider.currentSelectedRequest!, index: index, context: context); + }); + }, + ), + ], + ); + })); + return showModalBottomSheet( context: context, @@ -465,166 +808,165 @@ class ServiceRequestBottomSheet { isScrollControlled: true, backgroundColor: Colors.transparent, builder: (context) => Consumer(builder: (context, serviceRequestProvider, child) { - return Container( - clipBehavior: Clip.antiAlias, - margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), - decoration: BoxDecoration( - color: AppColor.background(context), - borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), - ), - padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const SizedBox().indicatorWidget(), - 8.height, - Align( - alignment: AlignmentDirectional.centerStart, - child: context.translation.selectActivityType.bottomSheetHeadingTextStyle(context), - ), - 16.height, - ListView.builder( - shrinkWrap: true, - padding: EdgeInsets.zero, - itemCount: items.length, - itemBuilder: (context, index) { - final item = items[index]; - return listItem( - icon: item['icon']!, - heading: item['heading']!, - subHeading: item['subHeading']!, - context: context, - onTap: () { - onItemTap(serviceRequest: serviceRequestProvider.currentSelectedRequest!, index: index, context: context); - }); - }, - ), - ], - ), - ); + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox().indicatorWidget(), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.selectActivityType.bottomSheetHeadingTextStyle(context), + ), + 16.height, + ListView.builder( + shrinkWrap: true, + padding: EdgeInsets.zero, + itemCount: items.length, + itemBuilder: (context, index) { + final item = items[index]; + return listItem( + icon: item['icon']!, + heading: item['heading']!, + subHeading: item['subHeading']!, + context: context, + onTap: () { + onItemTap(serviceRequest: serviceRequestProvider.currentSelectedRequest!, index: index, context: context); + }); + }, + ), + ], + ).bottomSheetContainer(context); })); } static Future actionBottomSheet({required BuildContext context, required String title, String? button1Text, String? button2Text, VoidCallback? button1Tap, VoidCallback? button2Tap}) { - return showModalBottomSheet( + return buildBottomSheetParentWithConsumer( context: context, - useSafeArea: true, - isScrollControlled: true, - backgroundColor: Colors.transparent, - builder: (context) => Consumer(builder: (context, serviceRequestProvider, child) { - return Container( - clipBehavior: Clip.antiAlias, - margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), - decoration: BoxDecoration( - color: Theme.of(context).scaffoldBackgroundColor, - borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), - ), - padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 12.toScreenHeight), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const SizedBox().indicatorWidget(), - 8.height, - Align( - alignment: AlignmentDirectional.centerStart, - child: title.bottomSheetHeadingTextStyle(context), - ), - 41.height, - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - AppFilledButton( - label: button1Text ?? context.translation.no, - loading: false, - buttonColor: AppColor.white60, - textColor: AppColor.black10, - onPressed: button1Tap ?? - () async { - Navigator.pop(context); - // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.serviceRequest); - // Navigator.pop(context, true); - }, - ).expanded, - 12.width, - AppFilledButton( - label: context.translation.yes, - buttonColor: AppColor.primary10, - loading: false, - onPressed: button2Tap, - ).expanded, - ], - ) - ], - ), - ); - })); - } + childWidget: Consumer(builder: (context, serviceRequestProvider, child) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox().indicatorWidget(), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: title.bottomSheetHeadingTextStyle(context), + ), + 41.height, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + AppFilledButton( + label: button1Text ?? context.translation.no, + loading: false, + buttonColor: AppColor.white60, + textColor: AppColor.black10, + onPressed: button1Tap ?? + () async { + Navigator.pop(context); + // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.serviceRequest); + // Navigator.pop(context, true); + }, + ).expanded, + 12.width, + AppFilledButton( + label: context.translation.yes, + buttonColor: AppColor.primary10, + loading: false, + onPressed: button2Tap, + ).expanded, + ], + ) + ], + ); + })); + - static Future feedBackBottomSheet({required BuildContext context}) { - final GlobalKey _formKey = GlobalKey(); return showModalBottomSheet( context: context, useSafeArea: true, isScrollControlled: true, backgroundColor: Colors.transparent, builder: (context) => Consumer(builder: (context, serviceRequestProvider, child) { - return Container( - clipBehavior: Clip.antiAlias, - margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), - decoration: BoxDecoration( - color: AppColor.background(context), - borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), - ), - padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 16.toScreenHeight), - child: Form( - key: _formKey, - child: SingleChildScrollView( - child: StatefulBuilder(builder: (context, setState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const SizedBox().indicatorWidget(), - 8.height, - Align( - alignment: AlignmentDirectional.centerStart, - child: context.translation.feedBack.bottomSheetHeadingTextStyle(context), - ), - 21.height, - AppTextFormField( - labelText: context.translation.comments, - textInputType: TextInputType.multiline, - labelStyle: AppTextStyles.textFieldLabelStyle, - showWithoutDecoration: true, - backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, - alignLabelWithHint: true, - onChange: (text) { - serviceRequestProvider.currentSelectedRequest?.comments = text; - }, - onSaved: (text) { - serviceRequestProvider.currentSelectedRequest?.comments = text; - }, - ), - 16.height, - AppFilledButton( - label: context.translation.fixed, - buttonColor: AppColor.green70, - loading: false, - onPressed: () {}, - ), - ], - ); - }), + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox().indicatorWidget(), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: title.bottomSheetHeadingTextStyle(context), ), - ), - ); + 41.height, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + AppFilledButton( + label: button1Text ?? context.translation.no, + loading: false, + buttonColor: AppColor.white60, + textColor: AppColor.black10, + onPressed: button1Tap ?? + () async { + Navigator.pop(context); + // await snapshot.updateRequest(user: userProvider.user, request: serviceRequestProvider.serviceRequest); + // Navigator.pop(context, true); + }, + ).expanded, + 12.width, + AppFilledButton( + label: context.translation.yes, + buttonColor: AppColor.primary10, + loading: false, + onPressed: button2Tap, + ).expanded, + ], + ) + ], + ).bottomSheetContainer(context); })); } - static Future nurseTakeActionBottomSheet({required BuildContext context}) { - bool acknowledge = false; - final GlobalKey _formKey = GlobalKey(); - Uint8List? newSignature; - String ?nurseSignature; + static Future feedBackBottomSheet({required BuildContext context}) { + + return buildBottomSheetParentWithConsumer( + context: context, + childWidget: Consumer(builder: (context, serviceRequestProvider, child) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox().indicatorWidget(), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.feedBack.bottomSheetHeadingTextStyle(context), + ), + 21.height, + AppTextFormField( + labelText: context.translation.comments, + textInputType: TextInputType.multiline, + labelStyle: AppTextStyles.textFieldLabelStyle, + showWithoutDecoration: true, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + alignLabelWithHint: true, + onChange: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + onSaved: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + ), + 16.height, + AppFilledButton( + label: context.translation.fixed, + buttonColor: AppColor.green70, + loading: false, + onPressed: () {}, + ), + ], + ); + })); + return showModalBottomSheet( context: context, useSafeArea: true, @@ -632,10 +974,9 @@ class ServiceRequestBottomSheet { backgroundColor: Colors.transparent, builder: (context) => Consumer(builder: (context, serviceRequestProvider, child) { return Form( - key: _formKey, + // key: _formKey, child: SingleChildScrollView( child: StatefulBuilder(builder: (context, setState) { - return Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -643,95 +984,243 @@ class ServiceRequestBottomSheet { 8.height, Align( alignment: AlignmentDirectional.centerStart, - child: context.translation.pleaseConfirmTheIssueHasBeenResolved.bottomSheetHeadingTextStyle(context), - ), - 10.height, - Row( - children: [ - InkWell( - child: acknowledge - ? const Icon( - Icons.check_box, - color: AppColor.primary10, - ) - :const Icon( - Icons.check_box_outline_blank, - color: AppColor.neutral120, - ), - onTap: () { - setState(() { - acknowledge = !acknowledge; - }); - }, - ), - 6.width, - Flexible(child: context.translation.nurseAcknowledge.bodyText(context).custom(color: context.isDark ? AppColor.primary50 : AppColor.neutral120)), - ], + child: context.translation.feedBack.bottomSheetHeadingTextStyle(context), ), - 17.height, - ESignature( - title: '', - oldSignature: '', - newSignature: newSignature, - backgroundColor: AppColor.neutral100, - showShadow: false, - onSaved: (signature) { - if (signature == null || signature.isEmpty) return; - newSignature = signature; - nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + 21.height, + AppTextFormField( + labelText: context.translation.comments, + textInputType: TextInputType.multiline, + labelStyle: AppTextStyles.textFieldLabelStyle, + showWithoutDecoration: true, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + alignLabelWithHint: true, + onChange: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; + }, + onSaved: (text) { + serviceRequestProvider.currentSelectedRequest?.comments = text; }, ), - 36.height, - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - mainAxisSize: MainAxisSize.min, - children: [ - AppFilledButton( - label: context.translation.reject, - maxWidth: true, - buttonColor: Colors.white54, - textColor: AppColor.red30, - showBorder: true, - onPressed: () async { - _formKey.currentState?.save(); - if(newSignature!=null&&acknowledge){ - //TODO replace provider with new provider and also check workorder id is not correct. - Provider.of(context,listen: false).nurseReject(model: NurseActionModel( - workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!), - signatureNurse: nurseSignature, - )); - Navigator.pop(context); - - } - - }, - ).expanded, - const SizedBox( - width: 20, - ), - AppFilledButton( - label: context.translation.confirm, - maxWidth: true, - buttonColor: AppColor.green70, - onPressed: () async { - _formKey.currentState?.save(); - if(newSignature!=null&&acknowledge){ - //TODO replace provider with new provider and also check workorder id is not correct. - Provider.of(context,listen: false).nurseConfirm(model: NurseActionModel( - workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!), - signatureNurse: nurseSignature, - )); - Navigator.pop(context); - } - }, - ).expanded, - ], - ) + 16.height, + AppFilledButton( + label: context.translation.fixed, + buttonColor: AppColor.green70, + loading: false, + onPressed: () {}, + ), ], ); }), ), - ).bottomSheetContainer(context); + )..bottomSheetContainer(context); })); } + + static Future nurseTakeActionBottomSheet({required BuildContext context}) { + bool acknowledge = false; + Uint8List? newSignature; + String? nurseSignature; + return buildBottomSheetParentWithConsumer( + context: context, + childWidget: Consumer(builder: (context, serviceRequestProvider, child) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox().indicatorWidget(), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.pleaseConfirmTheIssueHasBeenResolved.bottomSheetHeadingTextStyle(context), + ), + 10.height, + Row( + children: [ + InkWell( + child: acknowledge + ? const Icon( + Icons.check_box, + color: AppColor.primary10, + ) + : const Icon( + Icons.check_box_outline_blank, + color: AppColor.neutral120, + ), + onTap: () { + acknowledge = !acknowledge; + }, + ), + 6.width, + Flexible(child: context.translation.nurseAcknowledge.bodyText(context).custom(color: context.isDark ? AppColor.primary50 : AppColor.neutral120)), + ], + ), + 17.height, + ESignature( + title: '', + oldSignature: '', + newSignature: newSignature, + backgroundColor: AppColor.neutral100, + showShadow: false, + onSaved: (signature) { + if (signature == null || signature.isEmpty) return; + newSignature = signature; + nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + }, + ), + 36.height, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.min, + children: [ + AppFilledButton( + label: context.translation.reject, + maxWidth: true, + buttonColor: Colors.white54, + textColor: AppColor.red30, + showBorder: true, + onPressed: () async { + if (newSignature != null && acknowledge) { + //TODO replace provider with new provider and also check workorder id is not correct. + Provider.of(context, listen: false).nurseReject( + model: NurseActionModel( + workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!), + signatureNurse: nurseSignature, + )); + Navigator.pop(context); + } + }, + ).expanded, + const SizedBox( + width: 20, + ), + AppFilledButton( + label: context.translation.confirm, + maxWidth: true, + buttonColor: AppColor.green70, + onPressed: () async { + if (newSignature != null && acknowledge) { + //TODO replace provider with new provider and also check workorder id is not correct. + Provider.of(context, listen: false).nurseConfirm( + model: NurseActionModel( + workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!), + signatureNurse: nurseSignature, + )); + Navigator.pop(context); + } + }, + ).expanded, + ], + ) + ], + ); + })); + + // + // return showModalBottomSheet( + // context: context, + // useSafeArea: true, + // isScrollControlled: true, + // backgroundColor: Colors.transparent, + // builder: (context) => Consumer(builder: (context, serviceRequestProvider, child) { + // return Form( + // key: _formKey, + // child: SingleChildScrollView( + // child: StatefulBuilder(builder: (context, setState) { + // return Column( + // crossAxisAlignment: CrossAxisAlignment.center, + // children: [ + // const SizedBox().indicatorWidget(), + // 8.height, + // Align( + // alignment: AlignmentDirectional.centerStart, + // child: context.translation.pleaseConfirmTheIssueHasBeenResolved.bottomSheetHeadingTextStyle(context), + // ), + // 10.height, + // Row( + // children: [ + // InkWell( + // child: acknowledge + // ? const Icon( + // Icons.check_box, + // color: AppColor.primary10, + // ) + // : const Icon( + // Icons.check_box_outline_blank, + // color: AppColor.neutral120, + // ), + // onTap: () { + // setState(() { + // acknowledge = !acknowledge; + // }); + // }, + // ), + // 6.width, + // Flexible(child: context.translation.nurseAcknowledge.bodyText(context).custom(color: context.isDark ? AppColor.primary50 : AppColor.neutral120)), + // ], + // ), + // 17.height, + // ESignature( + // title: '', + // oldSignature: '', + // newSignature: newSignature, + // backgroundColor: AppColor.neutral100, + // showShadow: false, + // onSaved: (signature) { + // if (signature == null || signature.isEmpty) return; + // newSignature = signature; + // nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + // }, + // ), + // 36.height, + // Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + // mainAxisSize: MainAxisSize.min, + // children: [ + // AppFilledButton( + // label: context.translation.reject, + // maxWidth: true, + // buttonColor: Colors.white54, + // textColor: AppColor.red30, + // showBorder: true, + // onPressed: () async { + // _formKey.currentState?.save(); + // if (newSignature != null && acknowledge) { + // //TODO replace provider with new provider and also check workorder id is not correct. + // Provider.of(context, listen: false).nurseReject( + // model: NurseActionModel( + // workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!), + // signatureNurse: nurseSignature, + // )); + // Navigator.pop(context); + // } + // }, + // ).expanded, + // const SizedBox( + // width: 20, + // ), + // AppFilledButton( + // label: context.translation.confirm, + // maxWidth: true, + // buttonColor: AppColor.green70, + // onPressed: () async { + // _formKey.currentState?.save(); + // if (newSignature != null && acknowledge) { + // //TODO replace provider with new provider and also check workorder id is not correct. + // Provider.of(context, listen: false).nurseConfirm( + // model: NurseActionModel( + // workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!), + // signatureNurse: nurseSignature, + // )); + // Navigator.pop(context); + // } + // }, + // ).expanded, + // ], + // ) + // ], + // ); + // }), + // ), + // ).bottomSheetContainer(context); + // })); + } } diff --git a/lib/service_request_latest/views/components/request_detail_view.dart b/lib/service_request_latest/views/components/request_detail_view.dart index 2b2d06c0..7c3ad051 100644 --- a/lib/service_request_latest/views/components/request_detail_view.dart +++ b/lib/service_request_latest/views/components/request_detail_view.dart @@ -15,6 +15,7 @@ import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/new_views/common_widgets/app_filled_button.dart'; import 'package:test_sa/new_views/common_widgets/default_app_bar.dart'; import 'package:test_sa/service_request_latest/views/components/action_button/footer_action_button.dart'; +import 'package:test_sa/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart'; import 'package:test_sa/service_request_latest/views/components/initial_visit_card.dart'; import 'package:test_sa/service_request_latest/views/components/timer_widget.dart'; import 'package:test_sa/service_request_latest/views/forms/asset_retired/asset_retired.dart'; @@ -109,7 +110,7 @@ class _RequestDetailViewState extends State { ), ), FooterActionButton.requestDetailsFooterWidget(status: 7, context: context), - TimerWidget(), + const TimerWidget(), ], ), ); @@ -331,7 +332,7 @@ class _RequestDetailViewState extends State { showBorder: true, onPressed: () async { // Navigator.push(context, MaterialPageRoute(builder: (context) => AssetRetired())); - Navigator.push(context, MaterialPageRoute(builder: (context) => const CreateNewRequest())); + ServiceRequestBottomSheet.initialVisitBottomSheet(context: context); }), ); }