From 4698a3325e42b64b30be226a4b8a5c5ef10f60e9 Mon Sep 17 00:00:00 2001 From: WaseemAbbasi22 Date: Tue, 13 May 2025 09:49:12 +0300 Subject: [PATCH 1/3] add validation for assistant employee start and end date --- .../update_device_transfer.dart | 116 +++++++++--------- 1 file changed, 61 insertions(+), 55 deletions(-) diff --git a/lib/views/pages/device_transfer/update_device_transfer.dart b/lib/views/pages/device_transfer/update_device_transfer.dart index fadbe12f..df824fa7 100644 --- a/lib/views/pages/device_transfer/update_device_transfer.dart +++ b/lib/views/pages/device_transfer/update_device_transfer.dart @@ -385,67 +385,71 @@ class _UpdateDeviceTransferState extends State { List _files = []; _update({required int status}) async { + _formKey.currentState!.save(); + if (_validateForm()) { + _formModel.statusValue = status; + _formModel.isSender = widget.isSender; + _formModel.assetTransferAttachments = []; + int workingHours = _formModel.tbsTimer?.endAt!.difference(_formModel.tbsTimer!.startAt!).inSeconds ?? 0; + + if (widget.isSender) { + _formModel.senderVisitTimers?.add( + VisitTimers( + id: 0, + startDateTime: _formModel.tbsTimer?.startAt?.toIso8601String(), + endDateTime: _formModel.tbsTimer?.endAt?.toIso8601String(), + workingHours: ((workingHours) / 60 / 60), + ), + ); + _formModel.assetTransferEngineerTimers = _formModel.senderVisitTimers; + } else { + _formModel.receiverVisitTimers?.add( + VisitTimers( + id: 0, + startDateTime: _formModel.tbsTimer?.startAt?.toIso8601String(), + endDateTime: _formModel.tbsTimer?.endAt?.toIso8601String(), + workingHours: ((workingHours) / 60 / 60), + ), + ); + _formModel.assetTransferEngineerTimers = _formModel.receiverVisitTimers; + } + try { + for (var file in _files) { + String attachmentName = file.path; + if (attachmentName.contains("/")) { + attachmentName = file.path.split("/").last; + attachmentName = "$attachmentName|${base64Encode(file.readAsBytesSync())}"; + } + _formModel.assetTransferAttachments!.add(AssetTransferAttachment(id: 0, attachmentName: attachmentName)); + _formModel.attachments = _formModel.assetTransferAttachments; + } + } catch (error) { + print(error); + } + await _deviceTransferProvider.updateRequest(context, model: _formModel); + } + } + + bool _validateForm() { if (_formModel.tbsTimer?.startAt == null) { - await Fluttertoast.showToast(msg: "Working Hours Required"); + Fluttertoast.showToast(msg: "Working Hours Required"); return false; } if (_formModel.tbsTimer?.endAt == null || isTimerRunning) { - await Fluttertoast.showToast(msg: "Please Stop The Timer"); + Fluttertoast.showToast(msg: "Please Stop The Timer"); return false; } - if (!(_formKey.currentState!.validate())) { - setState(() {}); - return false; - } - _formKey.currentState!.save(); - - _formModel.statusValue = status; - _formModel.isSender = widget.isSender; - _formModel.assetTransferAttachments = []; - int workingHours = _formModel.tbsTimer?.endAt!.difference(_formModel.tbsTimer!.startAt!).inSeconds?? 0; - - if (widget.isSender) { - _formModel.senderVisitTimers?.add( - VisitTimers( - id: 0, - startDateTime: _formModel.tbsTimer?.startAt?.toIso8601String(), - endDateTime: _formModel.tbsTimer?.endAt?.toIso8601String(), - workingHours: ((workingHours) / 60 / 60), - ), - ); - _formModel.assetTransferEngineerTimers = _formModel.senderVisitTimers; - } else { - _formModel.receiverVisitTimers?.add( - VisitTimers( - id: 0, - startDateTime: _formModel.tbsTimer?.startAt?.toIso8601String(), - endDateTime: _formModel.tbsTimer?.endAt?.toIso8601String(), - workingHours: ((workingHours) / 60 / 60), - ), - ); - _formModel.assetTransferEngineerTimers = _formModel.receiverVisitTimers; - } - try { - for (var file in _files) { - String attachmentName = file.path; - if (attachmentName.contains("/")) { - attachmentName = file.path.split("/").last; - attachmentName = "$attachmentName|${base64Encode(file.readAsBytesSync())}"; - } - // if (widget.isSender) { - _formModel.assetTransferAttachments!.add(AssetTransferAttachment(id: 0, attachmentName: attachmentName)); - _formModel.attachments = _formModel.assetTransferAttachments; - // } - // else { - // _formModel.receiverAttachments!.add(AssetTransferAttachment(id: 0, attachmentName: attachmentName)); - // _formModel.attachments = _formModel.receiverAttachments; - // } + if (_formModel.assistantEmployees != null) { + if (_formModel.modelAssistantEmployees?.startDate == null) { + Fluttertoast.showToast(msg: "Please Select Assistant Employee Start Time"); + return false; + } + if (_formModel.modelAssistantEmployees?.endDate == null) { + Fluttertoast.showToast(msg: "Please Select Assistant Employee End Time"); + return false; } - } catch (error) { - print(error); } - - await _deviceTransferProvider.updateRequest(context, model: _formModel); + return true; } @override @@ -472,10 +476,12 @@ class _UpdateDeviceTransferState extends State { : (widget.model.receiverVisitTimers?.fold(0.0, (sum, item) => (sum ?? 0) + DateTime.parse(item.endDateTime!).difference(DateTime.parse(item.startDateTime!)).inSeconds) ?? 0); bool isTimerEnable = widget.isSender ? (!(_formModel.senderMachineStatusValue == 3)) : (!(_formModel.receiverMachineStatusValue == 3)); return Scaffold( - appBar: DefaultAppBar(title: context.translation.transferAsset, + appBar: DefaultAppBar( + title: context.translation.transferAsset, onWillPopScope: () { _update(status: 0); - },), + }, + ), key: _scaffoldKey, body: SafeArea( child: LoadingManager( From b320e3751a5d356e108031d6ea9d613999263be4 Mon Sep 17 00:00:00 2001 From: WaseemAbbasi22 Date: Sun, 18 May 2025 11:48:08 +0300 Subject: [PATCH 2/3] add code for nurse edit gas refill request --- lib/controllers/api_routes/urls.dart | 1 + .../providers/api/gas_refill_provider.dart | 28 ++ lib/models/new_models/gas_refill_model.dart | 14 + lib/models/new_models/mapped_sites.dart | 6 +- .../pages/gas_refill_request_form.dart | 355 ++++++++++++++++++ .../widgets/request_item_view_list.dart | 7 +- .../user/gas_refill/gas_refill_details.dart | 12 +- 7 files changed, 413 insertions(+), 10 deletions(-) diff --git a/lib/controllers/api_routes/urls.dart b/lib/controllers/api_routes/urls.dart index 0e76394e..bd39955c 100644 --- a/lib/controllers/api_routes/urls.dart +++ b/lib/controllers/api_routes/urls.dart @@ -241,6 +241,7 @@ class URLs { static get getGasStatus => "$_baseUrl/Lookups/GetLookup?lookupEnum=609"; // get static get requestGasRefill => "$_baseUrl/GasRefill/AddGasRefillFromMobile"; // get static get updateGasRefill => "$_baseUrl/GazRefill/UpdateGazRefill"; // get + static get updateGasRefillByNurse => "$_baseUrl/GazRefill/UpdateGasRefillByNurseForMobile"; //update gas refill by nurse static get getGasRefill => "$_baseUrl/GazRefill/GetGazRefills"; // get // static get getGasRefillById => "$_baseUrl/GazRefill/GetGazRefillById"; // get older endpoint.. static get getGasRefillById => "$_baseUrl/GasRefill/GetGasRefillById"; // get diff --git a/lib/controllers/providers/api/gas_refill_provider.dart b/lib/controllers/providers/api/gas_refill_provider.dart index f6c94914..8e6a3b5c 100644 --- a/lib/controllers/providers/api/gas_refill_provider.dart +++ b/lib/controllers/providers/api/gas_refill_provider.dart @@ -12,6 +12,7 @@ import 'package:test_sa/models/hospital.dart'; import 'package:test_sa/models/new_models/gas_refill_model.dart'; import 'package:test_sa/models/timer_model.dart'; import 'package:test_sa/models/user.dart'; +import 'package:test_sa/views/pages/user/gas_refill/update_gas_refill_request.dart'; import '../../../new_views/common_widgets/app_lazy_loading.dart'; @@ -138,6 +139,33 @@ class GasRefillProvider extends ChangeNotifier { print(error); } } + Future updateGasRefillRequestByNurse({ + required BuildContext context, + required GasRefillModel model, + }) async { + late Response response; + try { + showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); + response = await ApiManager.instance.post(URLs.updateGasRefillByNurse, body: model.toJson()); + stateCode = response.statusCode; + if (response.statusCode >= 200 && response.statusCode < 300) { + if (items != null) { + reset(); + notifyListeners(); + } + Fluttertoast.showToast(msg: context.translation.createdSuccessfully); + Navigator.pop(context); + } else { + Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest} :${json.decode(response.body)['message']}"); + } + Navigator.pop(context); + } catch (error) { + stateCode = -1; + notifyListeners(); + Navigator.pop(context); + print(error); + } + } Future updateGasRefill({required int status, required GasRefillModel model}) async { isLoading = true; diff --git a/lib/models/new_models/gas_refill_model.dart b/lib/models/new_models/gas_refill_model.dart index 6d1ac30e..23e3fb45 100644 --- a/lib/models/new_models/gas_refill_model.dart +++ b/lib/models/new_models/gas_refill_model.dart @@ -36,6 +36,10 @@ class GasRefillModel { this.assignedEmployee, this.status, this.comment, + this.mapSite, + this.mappedFloor, + this.mappedBuilding, + this.mappedDepartment, this.techComment, this.gasRefillDetails, this.localEngineerSignature, @@ -132,12 +136,21 @@ class GasRefillModel { // } catch (e) { // print(e); // } + print('building # ${json['building']}'); + print('department # ${json['department']}'); + print('floor # ${json['floor']}'); + engSignature = json['engSignature']; nurseSignature = json['nurseSignature']; site = json['site'] != null ? Site.fromJson(json['site']) : null; building = json['building'] != null ? Building.fromJson(json['building']) : null; floor = json['floor'] != null ? Floor.fromJson(json['floor']) : null; department = json['department'] != null ? Department.fromJson(json['department']) : null; + mapSite = json['site'] != null ? MappedSite.fromJson(json['site']) : null; + print('site i got is ::${mapSite?.toJson()}'); + mappedBuilding = mapSite?.buildings?.firstWhere((element) => element.identifier == building?.identifier, orElse: () => MappedBuilding()); + mappedFloor = mappedBuilding?.floors?.firstWhere((element) => element.identifier == floor?.identifier, orElse: () => MappedFloor()); + mappedDepartment = mappedFloor?.departments?.firstWhere((element) => element.identifier == department?.identifier, orElse: () => MappedDepartment()); assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null; status = json['status'] != null ? Lookup.fromJson(json['status']) : null; if (json['gasRefillDetails'] != null) { @@ -150,6 +163,7 @@ class GasRefillModel { Map toJson() { final map = {}; + map['id'] = id ?? 0; map['gasTypeId'] = gasRefillDetails?[0].gasType?.id; map['cylinderTypeId'] = gasRefillDetails?[0].cylinderType?.id; diff --git a/lib/models/new_models/mapped_sites.dart b/lib/models/new_models/mapped_sites.dart index 9034aa77..63b9874c 100644 --- a/lib/models/new_models/mapped_sites.dart +++ b/lib/models/new_models/mapped_sites.dart @@ -239,7 +239,7 @@ class MappedBuilding extends Base { customerId = json['customerId']; clientBuildingId = json['clientBuildingId']; clientBuildingName = json['clientBuildingName']; - name = clientBuildingName; + name = clientBuildingName??json['name']; floors = (json['floors'] as List?)?.map((e) => MappedFloor.fromJson(e)).toList(); } @@ -274,7 +274,7 @@ class MappedFloor extends Base { buildingId = json['buildingId']; clientFloorId = json['clientFloorId']; clientFloorName = json['clientFloorName']; - name = clientFloorName; + name = clientFloorName??json['name']; departments = (json['departments'] as List?)?.map((e) => MappedDepartment.fromJson(e)).toList(); } @@ -308,7 +308,7 @@ class MappedDepartment extends Base { floorId = json['floorId']; departmentId = json['departmentId']; departmentName = json['departmentName']; - name = departmentName; + name = departmentName??json['name']; // rooms = json['rooms']; } diff --git a/lib/new_views/pages/gas_refill_request_form.dart b/lib/new_views/pages/gas_refill_request_form.dart index 916e7b78..8ed98320 100644 --- a/lib/new_views/pages/gas_refill_request_form.dart +++ b/lib/new_views/pages/gas_refill_request_form.dart @@ -330,3 +330,358 @@ class _GasRefillRequestFormState extends State { // }, // ), } + +//TODO uncommit this to use editable form for nurse side. + +// import 'dart:convert'; +// import 'dart:io'; +// import 'package:flutter/material.dart'; +// import 'package:fluttertoast/fluttertoast.dart'; +// import 'package:provider/provider.dart'; +// import 'package:test_sa/cm_module/utilities/service_request_utils.dart'; +// import 'package:test_sa/dashboard_latest/dashboard_provider.dart'; +// import 'package:test_sa/extensions/context_extension.dart'; +// import 'package:test_sa/extensions/int_extensions.dart'; +// import 'package:test_sa/extensions/text_extensions.dart'; +// import 'package:test_sa/extensions/widget_extensions.dart'; +// import 'package:test_sa/models/enums/user_types.dart'; +// import 'package:test_sa/models/lookup.dart'; +// import 'package:test_sa/models/new_models/gas_refill_model.dart'; +// import 'package:test_sa/models/new_models/mapped_sites.dart'; +// 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/app_text_form_field.dart'; +// import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart'; +// import 'package:test_sa/providers/gas_request_providers/cylinder_size_provider.dart'; +// import 'package:test_sa/providers/gas_request_providers/cylinder_type_provider.dart'; +// import 'package:test_sa/providers/gas_request_providers/gas_types_provider.dart'; +// import 'package:test_sa/providers/gas_request_providers/site_provider.dart'; +// import 'package:test_sa/providers/loading_list_notifier.dart'; +// +// import 'package:test_sa/cm_module/views/components/action_button/footer_action_button.dart'; +// import 'package:test_sa/views/widgets/images/multi_image_picker.dart'; +// import '../../controllers/providers/api/gas_refill_provider.dart'; +// import '../common_widgets/default_app_bar.dart'; +// +// class GasRefillRequestForm extends StatefulWidget { +// static const String routeName = "/gas_refill_request_form"; +// final GasRefillModel? gasModel; +// final GasRefillDetails? gasRefillDetails; +// +// const GasRefillRequestForm({this.gasModel, this.gasRefillDetails, Key? key}) : super(key: key); +// +// @override +// State createState() => _GasRefillRequestFormState(); +// } +// +// class _GasRefillRequestFormState extends State { +// late GasRefillDetails _currentDetails; +// late GasRefillModel _gasModel; +// Lookup? _requestedQuantity; +// final TextEditingController _commentController = TextEditingController(); +// GasRefillProvider? _gasRefillProvider; +// List _files = []; +// +// static List gasQuantity = [ +// Lookup(name: "1", id: 1, value: 1), +// Lookup(name: "2", id: 2, value: 2), +// Lookup(name: "3", id: 3, value: 3), +// Lookup(name: "4", id: 4, value: 4), +// Lookup(name: "5", id: 5, value: 5) +// ]; +// +// @override +// void initState() { +// super.initState(); +// _gasRefillProvider ??= Provider.of(context, listen: false); +// _currentDetails = widget.gasRefillDetails ?? GasRefillDetails(); +// _gasModel = widget.gasModel ?? GasRefillModel(gasRefillDetails: []); +// if (_gasModel.gasRefillAttachments != null && _gasModel.gasRefillAttachments!.isNotEmpty) { +// _files.addAll(_gasModel.gasRefillAttachments!.map((e) => File(e.attachmentName!)).toList()); +// } +// if (widget.gasRefillDetails != null && widget.gasRefillDetails?.requestedQty != null) { +// _requestedQuantity = Lookup(name: "1", id: 1, value: int.parse(widget.gasRefillDetails!.requestedQty!.toStringAsFixed(0))); +// } +// } +// +// @override +// void dispose() { +// super.dispose(); +// } +// +// @override +// Widget build(BuildContext context) { +// return Scaffold( +// appBar: DefaultAppBar(title: widget.gasModel == null ? context.translation.newGasRefillRequest : context.translation.updateRequest), +// body: Column( +// children: [ +// 12.height, +// SingleChildScrollView( +// child: Column( +// children: [ +// SingleItemDropDownMenu( +// context: context, +// title: context.translation.gasType, +// initialValue: _currentDetails.gasType, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// showAsBottomSheet: true, +// onSelect: (value) { +// _currentDetails.gasType = value; +// }, +// ), +// 8.height, +// SingleItemDropDownMenu( +// context: context, +// title: context.translation.cylinderType, +// initialValue: _currentDetails.cylinderType, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// onSelect: (value) { +// _currentDetails.cylinderType = value; +// }, +// ), +// 8.height, +// SingleItemDropDownMenu( +// context: context, +// title: context.translation.cylinderSize, +// initialValue: _currentDetails.cylinderSize, +// showAsBottomSheet: true, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// onSelect: (value) { +// _currentDetails.cylinderSize = value; +// }, +// ), +// 8.height, +// SingleItemDropDownMenu( +// context: context, +// title: context.translation.quantity, +// showAsBottomSheet: true, +// initialValue: _requestedQuantity, +// staticData: gasQuantity, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// onSelect: (value) { +// _requestedQuantity = value; +// _currentDetails.requestedQty = value?.value; +// }, +// ), +// 8.height, +// Row( +// children: [ +// SingleItemDropDownMenu( +// context: context, +// title: context.translation.site, +// initialValue: _gasModel.mapSite, +// showAsBottomSheet: true, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// onSelect: (value) { +// setState(() { +// _gasModel.mapSite = value; +// _gasModel.mappedBuilding = null; +// _gasModel.mappedFloor = null; +// _gasModel.mappedDepartment = null; +// }); +// }, +// ).expanded, +// 8.width, +// SingleItemDropDownMenu( +// context: context, +// title: context.translation.building, +// initialValue: _gasModel.mappedBuilding, +// enabled: _gasModel.mapSite?.buildings?.isNotEmpty ?? false, +// staticData: _gasModel.mapSite?.buildings ?? [], +// showAsBottomSheet: true, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// onSelect: (value) { +// setState(() { +// _gasModel.mappedBuilding = value; +// _gasModel.mappedFloor = null; +// _gasModel.mappedDepartment = null; +// }); +// }, +// ).expanded, +// ], +// ), +// 8.height, +// Row( +// children: [ +// SingleItemDropDownMenu( +// context: context, +// title: context.translation.floor, +// initialValue: _gasModel.mappedFloor, +// enabled: _gasModel.mappedBuilding?.floors?.isNotEmpty ?? false, +// staticData: _gasModel.mappedBuilding?.floors ?? [], +// showAsBottomSheet: true, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// onSelect: (value) { +// if (value != null) { +// setState(() { +// _gasModel.mappedFloor = value; +// _gasModel.department = null; +// }); +// } +// }, +// ).expanded, +// 8.width, +// SingleItemDropDownMenu( +// context: context, +// title: context.translation.department, +// initialValue: _gasModel.mappedDepartment, +// enabled: _gasModel.mappedFloor?.departments?.isNotEmpty ?? false, +// staticData: _gasModel.mappedFloor?.departments ?? [], +// showAsBottomSheet: true, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// onSelect: (value) { +// _gasModel.mappedDepartment = value; +// }, +// ).expanded, +// ], +// ), +// 8.height, +// AppTextFormField( +// labelText: context.translation.callComments, +// labelStyle: AppTextStyles.tinyFont.copyWith(color: AppColor.neutral120), +// textInputType: TextInputType.multiline, +// alignLabelWithHint: true, +// initialValue: _gasModel.comment, +// backgroundColor: AppColor.neutral100, +// showShadow: false, +// controller: _commentController, +// onChange: (value) { +// _gasModel.comment = value; +// }, +// onSaved: (value) {}, +// ), +// 8.height, +// MultiFilesPicker( +// label: context.translation.attachFiles, +// files: _files, +// buttonColor: AppColor.black10, +// onlyImages: false, +// buttonIcon: 'image-plus'.toSvgAsset(color: AppColor.neutral120), +// ), +// ], +// ).toShadowContainer(context, padding: 10).paddingOnly(start: 16, end: 16, top: 16), +// ).expanded, +// 16.height, +// FooterActionButton.footerContainer( +// child: AppFilledButton(label: widget.gasModel == null ? context.translation.submitRequest : context.translation.updateRequest, maxWidth: true, onPressed: _submit)), +// ], +// ), +// ); +// } +// +// Future _submit() async { +// if (await validateRequest()) { +// _gasModel.gasRefillDetails = []; +// _gasModel.gasRefillDetails?.add(_currentDetails); +// _gasModel.gasRefillAttachments = []; +// for (var item in _files) { +// _gasModel.gasRefillAttachments?.add(GasRefillAttachments( +// id: 0, gasRefillId: _gasModel.id ?? 0, attachmentName: ServiceRequestUtils.isLocalUrl(item.path) ? "${item.path.split("/").last}|${base64Encode(item.readAsBytesSync())}" : item.path)); +// } +// if (widget.gasModel != null) { +// //TODO need to call api here for update for nurse APi has issue need to discuss with backend.. +// await _gasRefillProvider?.updateGasRefillRequestByNurse( +// context: context, +// model: _gasModel, +// ); +// } else { +// await _gasRefillProvider?.addGasRefillRequest( +// context: context, +// model: _gasModel, +// ); +// } +// if (_gasRefillProvider?.stateCode == 200) { +// DashBoardProvider dashBoardProvider = Provider.of(context, listen: false); +// dashBoardProvider.refreshDashboard(context: context, userType: UsersTypes.nurse); +// } +// } +// } +// +// Future validateRequest() async { +// if (_currentDetails.gasType == null) { +// await Fluttertoast.showToast(msg: "Please Select Gas Type"); +// return false; +// } +// if (_gasModel.mapSite == null) { +// await Fluttertoast.showToast(msg: "Please Select Site"); +// return false; +// } +// if (_gasModel.mappedBuilding == null) { +// await Fluttertoast.showToast(msg: "Please Select Building"); +// return false; +// } +// if (_gasModel.mappedFloor == null) { +// await Fluttertoast.showToast(msg: "Please Select Floor"); +// return false; +// } +// if (_gasModel.mappedDepartment == null) { +// await Fluttertoast.showToast(msg: "Please Select Department"); +// return false; +// } +// return true; +// } +// +// //older code.... +// // if (_gasModel.gasRefillDetails?.isEmpty ?? true) +// // AppFilledButton( +// // label: context.translation.add, +// // maxWidth: true, +// // textColor: Colors.white, +// // buttonColor: context.isDark ? AppColor.neutral60 : AppColor.neutral50, +// // onPressed: _add, +// // ), +// // ListView.builder( +// // shrinkWrap: true, +// // itemCount: _gasModel.gasRefillDetails?.length, +// // padding: const EdgeInsets.only(top: 12, bottom: 24), +// // physics: const NeverScrollableScrollPhysics(), +// // itemBuilder: (context, index) { +// // return Column( +// // crossAxisAlignment: CrossAxisAlignment.start, +// // children: [ +// // Row( +// // mainAxisAlignment: MainAxisAlignment.spaceBetween, +// // crossAxisAlignment: CrossAxisAlignment.start, +// // children: [ +// // Column( +// // crossAxisAlignment: CrossAxisAlignment.start, +// // children: [ +// // (_gasModel.gasRefillDetails![index].gasType?.name ?? "").heading5(context), +// // 8.height, +// // ("${context.translation.quantity}: ${_gasModel.gasRefillDetails![index].requestedQty}").bodyText(context), +// // ("${context.translation.cylinderSize}: ${_gasModel.gasRefillDetails![index].cylinderSize?.name}").bodyText(context), +// // ("${context.translation.cylinderType}: ${_gasModel.gasRefillDetails![index].cylinderType?.name}").bodyText(context), +// // ], +// // ), +// // Container( +// // height: 48.toScreenWidth, +// // width: 48.toScreenWidth, +// // decoration: BoxDecoration( +// // borderRadius: BorderRadius.circular(100), +// // border: Border.all(color: context.isDark ? AppColor.neutral50 : AppColor.neutral30), +// // ), +// // padding: EdgeInsets.symmetric(vertical: 12.toScreenHeight), +// // child: "trash".toSvgAsset(fit: BoxFit.fitHeight, color: context.isDark ? AppColor.red40 : AppColor.red50), +// // ).onPress(() { +// // _delete(index); +// // }), +// // ], +// // ), +// // const Divider().defaultStyle(context), +// // ("${context.translation.site}: ${_gasModel.site?.custName}").bodyText(context), +// // ("${context.translation.building}: ${_gasModel.building?.name}").bodyText(context), +// // ("${context.translation.floor}: ${_gasModel.floor?.name}").bodyText(context), +// // ("${context.translation.department}: ${_gasModel.department?.departmentName}").bodyText(context), +// // ], +// // ).toShadowContainer(context); +// // }, +// // ), +// } diff --git a/lib/new_views/pages/land_page/widgets/request_item_view_list.dart b/lib/new_views/pages/land_page/widgets/request_item_view_list.dart index 0e4a6d88..6d3767b7 100644 --- a/lib/new_views/pages/land_page/widgets/request_item_view_list.dart +++ b/lib/new_views/pages/land_page/widgets/request_item_view_list.dart @@ -27,18 +27,18 @@ class RequestItemViewList extends StatelessWidget { shrinkWrap: true, itemBuilder: (cxt, index) { if (isLoading) return const SizedBox().toRequestShimmer(cxt, isLoading); - switch(list[index].transactionType){ + switch (list[index].transactionType) { case 1: return ServiceRequestItemView(requestDetails: list[index]); case 2: - return GasRefillItemView(requestDetails: list[index]); + return GasRefillItemView(requestDetails: list[index]); case 3: return DeviceItemView(requestDetails: list[index]); case 4: return PpmItemView(requestDetails: list[index]); case 5: return RecurrentWoItemView(requestDetails: list[index]); - case 6: + case 6: return TaskRequestItemView(requestDetails: list[index]); default: Container( @@ -46,7 +46,6 @@ class RequestItemViewList extends StatelessWidget { width: double.infinity, color: Colors.grey, ); - } // bool isServiceRequest = list[index].transactionType == 1; // bool isGasRefill = list[index].transactionType == 2; diff --git a/lib/views/pages/user/gas_refill/gas_refill_details.dart b/lib/views/pages/user/gas_refill/gas_refill_details.dart index 9a3a386f..62bdbe68 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -11,6 +11,7 @@ import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/string_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/new_views/common_widgets/app_filled_button.dart'; +import 'package:test_sa/new_views/pages/gas_refill_request_form.dart'; import 'package:test_sa/views/pages/user/gas_refill/update_gas_refill_request.dart'; import 'package:test_sa/views/widgets/images/files_list.dart'; import 'package:test_sa/views/widgets/loaders/app_loading.dart'; @@ -73,7 +74,6 @@ class _GasRefillDetailsPageState extends State { padding: const EdgeInsets.all(16), child: informationCard(_model), ).expanded, - if (_userProvider.user!.type == UsersTypes.engineer && (_model.status!.value! != 2)) ...[ AppFilledButton( onPressed: () async { @@ -82,11 +82,17 @@ class _GasRefillDetailsPageState extends State { }, label: context.translation.updateRequest, ).paddingAll(16) + ] - // else if(_model.status!.value! == 0)...[ + //TODO need to uncomment this to enable nurse edit gas refill request. + // else if (_model.status!.value! == 0) ...[ // AppFilledButton( // onPressed: () async { - // await Navigator.of(context).push(MaterialPageRoute(builder: (_) => UpdateGasRefillRequest(gasRefillModel: _model))); + // await Navigator.of(context).push(MaterialPageRoute( + // builder: (_) => GasRefillRequestForm( + // gasModel: _model, + // gasRefillDetails: _model.gasRefillDetails?[0], + // ))); // // getVisitData(); // }, // label: context.translation.updateRequest, From 0996801f668265af90109562fe6dc42c2c57428d Mon Sep 17 00:00:00 2001 From: WaseemAbbasi22 Date: Mon, 19 May 2025 17:16:14 +0300 Subject: [PATCH 3/3] notification testing done for all type of request on dev env. --- lib/controllers/api_routes/urls.dart | 8 +- .../firebase_notification_manger.dart | 82 ++++-- lib/models/system_notification_model.dart | 5 + .../service_request_detail_provider.dart | 2 + .../service_request_detail_main_view.dart | 136 +++++----- .../pm_module/ppm_wo/ppm_details_page.dart | 7 +- .../device_transfer_details.dart | 235 +++++++++--------- .../widgets/requests/request_status.dart | 2 +- 8 files changed, 268 insertions(+), 209 deletions(-) diff --git a/lib/controllers/api_routes/urls.dart b/lib/controllers/api_routes/urls.dart index bd39955c..617065a9 100644 --- a/lib/controllers/api_routes/urls.dart +++ b/lib/controllers/api_routes/urls.dart @@ -4,12 +4,12 @@ class URLs { static const String appReleaseBuildNumber = "14"; // static const host1 = "https://atomsm.hmg.com"; // production url - // static const host1 = "https://atomsmdev.hmg.com"; // local DEV url - static const host1 = "https://atomsmuat.hmg.com"; // local UAT url + static const host1 = "https://atomsmdev.hmg.com"; // local DEV url + // static const host1 = "https://atomsmuat.hmg.com"; // local UAT url // static String _baseUrl = "$_host/mobile"; - // static final String _baseUrl = "$_host/v2/mobile"; // new V2 apis - static final String _baseUrl = "$_host/mobile"; // host local UAT + static final String _baseUrl = "$_host/v2/mobile"; // new V2 apis + // static final String _baseUrl = "$_host/mobile"; // host local UAT // static final String _baseUrl = "$_host/v3/mobile"; // new V3 apis static String _host = host1; diff --git a/lib/controllers/notification/firebase_notification_manger.dart b/lib/controllers/notification/firebase_notification_manger.dart index 0f026c62..43dabb24 100644 --- a/lib/controllers/notification/firebase_notification_manger.dart +++ b/lib/controllers/notification/firebase_notification_manger.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:developer'; import 'dart:io'; import 'package:firebase_messaging/firebase_messaging.dart'; @@ -6,12 +7,17 @@ import 'package:flutter/material.dart'; import 'package:google_api_availability/google_api_availability.dart'; import 'package:huawei_push/huawei_push.dart' as h_push; import 'package:test_sa/controllers/notification/notification_manger.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/models/all_requests_and_count_model.dart'; import 'package:test_sa/models/device/device_transfer.dart'; import 'package:test_sa/models/new_models/gas_refill_model.dart'; import 'package:test_sa/modules/cm_module/views/service_request_detail_main_view.dart'; import 'package:test_sa/modules/pm_module/ppm_wo/ppm_details_page.dart'; +import 'package:test_sa/modules/pm_module/recurrent_wo/recurrent_work_order_view.dart'; +import 'package:test_sa/modules/tm_module/tasks_wo/task_request_detail_view.dart'; import 'package:test_sa/views/pages/device_transfer/device_transfer_details.dart'; import 'package:test_sa/views/pages/user/gas_refill/gas_refill_details.dart'; +import 'package:test_sa/views/widgets/loaders/no_data_found.dart'; @pragma('vm:entry-point') Future firebaseMessagingBackgroundHandler(RemoteMessage message) async {} @@ -78,28 +84,67 @@ class FirebaseNotificationManger { static void handleMessage(context, Map messageData) { if (messageData["requestType"] != null && messageData["requestNumber"] != null) { Widget? serviceClass; - - if (messageData["requestType"] == "Service request to engineer") { - serviceClass = ServiceRequestDetailMain(requestId: messageData["requestNumber"] ?? ''); - } else if (messageData["requestType"] == "Gas Refill") { - serviceClass = GasRefillDetailsPage( - priority: messageData["priority"], - date: messageData["createdOn"], - model: GasRefillModel(id: int.parse(messageData["requestNumber"].toString())), - ); - } else if (messageData["requestType"] == "Asset Transfer") { - serviceClass = DeviceTransferDetails(model: DeviceTransfer(id: int.parse(messageData["requestNumber"].toString()))); - } else if (messageData["requestType"] == "PPM") { - serviceClass = PpmDetailsPage(requestId: int.parse(messageData["requestNumber"].toString())); + // PPM=1, + // ServiceRequestEngineer = 3, + // AssetTransfer=7, + // SparePartTransaction= 8, + // GasRefill=9, + // TechnicalRetirmentWO = 11, + // Recurrent = 12,​ + switch (messageData["transactionType"]) { + case 1: + serviceClass = PpmDetailsPage(requestId: int.parse(messageData["requestNumber"].toString())); + break; + //these three request are same corrective maintenance.... + case 3: + serviceClass = ServiceRequestDetailMain(requestId: messageData["requestNumber"] ?? ''); + break; + case 8: + serviceClass = ServiceRequestDetailMain(requestId: messageData["requestNumber"] ?? ''); + break; + case 11: + serviceClass = ServiceRequestDetailMain(requestId: messageData["requestNumber"] ?? ''); + break; + case 7: + serviceClass = DeviceTransferDetails(model: DeviceTransfer(id: int.parse(messageData["requestNumber"].toString()))); + break; + case 9: + serviceClass = GasRefillDetailsPage( + priority: messageData["priority"], + date: messageData["createdOn"], + model: GasRefillModel(id: int.parse(messageData["requestNumber"].toString())), + ); + break; + case 12: + serviceClass = RecurrentWorkOrderView(taskId: int.parse(messageData["requestNumber"].toString())); + //Didn't handle task request yet... + // case 6: + // serviceClass = TaskRequestDetailsView( + // taskId: int.parse(messageData["requestNumber"].toString()), + // requestDetails: RequestsDetails(nameOfType: messageData["sourceName"], status: messageData["statusName"], priority: messageData["priorityName"], date: messageData["createdDate"])); + // return; + default: + serviceClass = const Scaffold(body: Center(child: NoDataFound())); } + + // if (messageData["requestType"] == "Service request to engineer") { + // serviceClass = ServiceRequestDetailMain(requestId: messageData["requestNumber"] ?? ''); + // } else if (messageData["requestType"] == "Gas Refill") { + // serviceClass = GasRefillDetailsPage( + // priority: messageData["priority"], + // date: messageData["createdOn"], + // model: GasRefillModel(id: int.parse(messageData["requestNumber"].toString())), + // ); + // } else if (messageData["requestType"] == "Asset Transfer") { + // serviceClass = DeviceTransferDetails(model: DeviceTransfer(id: int.parse(messageData["requestNumber"].toString()))); + // } else if (messageData["requestType"] == "PPM") { + // serviceClass = PpmDetailsPage(requestId: int.parse(messageData["requestNumber"].toString())); + // } // else if (data["requestType"] == "WorkOrder") { // // } - - if (serviceClass != null) { - Navigator.of(context).push(MaterialPageRoute(builder: (_) => serviceClass!)); - } - } + Navigator.of(context).push(MaterialPageRoute(builder: (_) => serviceClass!)); + } } static initialized(BuildContext context) async { @@ -116,6 +161,7 @@ class FirebaseNotificationManger { if (message is Map) { Map remoteData = message; remoteData = remoteData["extras"]; + handleMessage(context, remoteData); } } catch (ex) { diff --git a/lib/models/system_notification_model.dart b/lib/models/system_notification_model.dart index 23154215..f307b289 100644 --- a/lib/models/system_notification_model.dart +++ b/lib/models/system_notification_model.dart @@ -13,6 +13,7 @@ class SystemNotificationModel { String? modifiedOn; String? priorityName; String? statusName; + int ? transactionType; SystemNotificationModel( {this.userId, @@ -28,6 +29,7 @@ class SystemNotificationModel { this.createdOn, this.modifiedOn, this.priorityName, + this.transactionType, this.statusName}); SystemNotificationModel.fromJson(Map? json) { @@ -48,6 +50,7 @@ class SystemNotificationModel { modifiedOn = json['modifiedOn']; priorityName = json['priorityName']; statusName = json['statusName']; + transactionType = json['transactionType']; } } @@ -68,6 +71,7 @@ class SystemNotificationModel { data['priorityName'] = priorityName; data['priority'] = priorityName; data['statusName'] = statusName; + data['transactionType'] = transactionType; return data; } @@ -87,6 +91,7 @@ class SystemNotificationModel { data['modifiedOn'] = modifiedOn; data['priorityName'] = priorityName; data['statusName'] = statusName; + data['transactionType'] = transactionType; return data; } } diff --git a/lib/modules/cm_module/service_request_detail_provider.dart b/lib/modules/cm_module/service_request_detail_provider.dart index 15f2644f..55df5224 100644 --- a/lib/modules/cm_module/service_request_detail_provider.dart +++ b/lib/modules/cm_module/service_request_detail_provider.dart @@ -243,6 +243,8 @@ class ServiceRequestDetailProvider extends ChangeNotifier { } else { isReadOnlyRequest = false; } + }else{ + currentWorkOrder =null; } isLoading = false; notifyListeners(); diff --git a/lib/modules/cm_module/views/service_request_detail_main_view.dart b/lib/modules/cm_module/views/service_request_detail_main_view.dart index 7d56634e..294c284b 100644 --- a/lib/modules/cm_module/views/service_request_detail_main_view.dart +++ b/lib/modules/cm_module/views/service_request_detail_main_view.dart @@ -12,6 +12,7 @@ import 'package:test_sa/modules/cm_module/service_request_detail_provider.dart'; import 'package:test_sa/modules/cm_module/views/components/bottom_sheets/service_request_bottomsheet.dart'; import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/new_views/common_widgets/default_app_bar.dart'; +import 'package:test_sa/views/widgets/loaders/no_data_found.dart'; import 'components/history_log_view.dart'; import 'components/service_request_detail_view.dart'; @@ -37,18 +38,18 @@ class _ServiceRequestDetailMainState extends State { }); } - Future getInitialData() async{ + Future getInitialData() async { bool isNurse = (Provider.of(context, listen: false).user?.type) == UsersTypes.normal_user; - _requestProvider = Provider.of(context, listen: false); + _requestProvider = Provider.of(context, listen: false); await _requestProvider.getWorkOrderById(id: widget.requestId); if (isNurse && (_requestProvider.currentWorkOrder?.data?.nextStep?.workOrderNextStepEnum == WorkOrderNextStepEnum.waitingForRequesterToConfirm)) { ServiceRequestBottomSheet.nurseVerifyArrivalBottomSheet(context: context); } _requestProvider.needVisitHelperModel = NeedVisitHelperModel( - workOrderId: _requestProvider.currentWorkOrder?.data?.requestId, - visitDate: _requestProvider.currentWorkOrder?.data?.needAVisitDateTime, - comment: _requestProvider.currentWorkOrder?.data?.needAVisitComment, - ); + workOrderId: _requestProvider.currentWorkOrder?.data?.requestId, + visitDate: _requestProvider.currentWorkOrder?.data?.needAVisitDateTime, + comment: _requestProvider.currentWorkOrder?.data?.needAVisitComment, + ); } @override @@ -72,72 +73,71 @@ class _ServiceRequestDetailMainState extends State { return true; }, child: Scaffold( - backgroundColor: AppColor.neutral100, - appBar: DefaultAppBar( - title: context.translation.cmDetails, - onBackPress: () { - stopTimer(); - Navigator.pop(context); - }, - actions: [ - isNurse - ? IconButton( - icon: 'qr'.toSvgAsset( - height: 24, - width: 24, + backgroundColor: AppColor.neutral100, + appBar: DefaultAppBar( + title: context.translation.cmDetails, + onBackPress: () { + stopTimer(); + Navigator.pop(context); + }, + actions: [ + isNurse + ? IconButton( + icon: 'qr'.toSvgAsset( + height: 24, + width: 24, + ), + onPressed: () { + ServiceRequestBottomSheet.getQRCodeBottomSheet(context: context); + }, + ) + : IconButton( + icon: const Icon(Icons.home), + onPressed: () { + // stopTimer(); + Navigator.pop(context); + }, ), - onPressed: () { - ServiceRequestBottomSheet.getQRCodeBottomSheet(context: context); - }, - ) - : IconButton( - icon: const Icon(Icons.home), - onPressed: () { - // stopTimer(); - Navigator.pop(context); + ], + ), + body: DefaultTabController( + length: 2, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + margin: EdgeInsets.only(left: 16.toScreenWidth, right: 16.toScreenWidth, top: 12.toScreenHeight), + decoration: BoxDecoration(color: context.isDark ? AppColor.neutral50 : AppColor.white10, borderRadius: BorderRadius.circular(10)), + child: TabBar( + //controller: _tabController, + padding: EdgeInsets.symmetric(vertical: 4.toScreenHeight, horizontal: 4.toScreenWidth), + labelColor: context.isDark ? AppColor.neutral30 : AppColor.black20, + unselectedLabelColor: context.isDark ? AppColor.neutral30 : AppColor.black20, + unselectedLabelStyle: AppTextStyles.bodyText, + labelStyle: AppTextStyles.bodyText, + indicatorPadding: EdgeInsets.zero, + indicatorSize: TabBarIndicatorSize.tab, + dividerColor: Colors.transparent, + indicator: BoxDecoration(color: context.isDark ? AppColor.neutral60 : AppColor.neutral110, borderRadius: BorderRadius.circular(7)), + onTap: (index) { + // setState(() {}); }, + tabs: [ + Tab(text: context.translation.details, height: 57.toScreenHeight), + Tab(text: context.translation.historyLogs, height: 57.toScreenHeight), + ], ), - ], - ), - body: DefaultTabController( - length: 2, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - margin: EdgeInsets.only(left: 16.toScreenWidth, right: 16.toScreenWidth, top: 12.toScreenHeight), - decoration: BoxDecoration(color: context.isDark ? AppColor.neutral50 : AppColor.white10, borderRadius: BorderRadius.circular(10)), - child: TabBar( - //controller: _tabController, - padding: EdgeInsets.symmetric(vertical: 4.toScreenHeight, horizontal: 4.toScreenWidth), - labelColor: context.isDark ? AppColor.neutral30 : AppColor.black20, - unselectedLabelColor: context.isDark ? AppColor.neutral30 : AppColor.black20, - unselectedLabelStyle: AppTextStyles.bodyText, - labelStyle: AppTextStyles.bodyText, - indicatorPadding: EdgeInsets.zero, - indicatorSize: TabBarIndicatorSize.tab, - dividerColor: Colors.transparent, - indicator: BoxDecoration(color: context.isDark ? AppColor.neutral60 : AppColor.neutral110, borderRadius: BorderRadius.circular(7)), - onTap: (index) { - // setState(() {}); - }, - tabs: [ - Tab(text: context.translation.details, height: 57.toScreenHeight), - Tab(text: context.translation.historyLogs, height: 57.toScreenHeight), - ], ), - ), - 12.height, - TabBarView( - children: [ - ServiceRequestDetailView(), - const HistoryLogView(), - ], - ).expanded, - ], - ), - ), - ), + 12.height, + TabBarView( + children: [ + ServiceRequestDetailView(), + const HistoryLogView(), + ], + ).expanded, + ], + ), + )), ); } } diff --git a/lib/modules/pm_module/ppm_wo/ppm_details_page.dart b/lib/modules/pm_module/ppm_wo/ppm_details_page.dart index b39180fd..78d8cefe 100644 --- a/lib/modules/pm_module/ppm_wo/ppm_details_page.dart +++ b/lib/modules/pm_module/ppm_wo/ppm_details_page.dart @@ -9,6 +9,7 @@ import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/plan_preventive_visit/plan_preventive_visit_model.dart'; import 'package:test_sa/new_views/common_widgets/default_app_bar.dart'; import 'package:test_sa/views/widgets/loaders/app_loading.dart'; +import 'package:test_sa/views/widgets/loaders/no_data_found.dart'; import 'package:test_sa/views/widgets/requests/request_status.dart'; import '../../../../../controllers/providers/api/user_provider.dart'; @@ -64,7 +65,7 @@ class _PpmDetailsPageState extends State { PlanPreventiveVisit? planPreventiveVisit = ppmProvider.planPreventiveVisit; return ppmProvider.isLoading ? const ALoading() - : Column(children: [ + :planPreventiveVisit!=null? Column(children: [ SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -80,7 +81,7 @@ class _PpmDetailsPageState extends State { // if (planPreventiveVisit?.visitStatus != null) 8.width, StatusLabel( label: planPreventiveVisit?.visitStatus!.name!, - id: planPreventiveVisit!.visitStatus!.id!, + id: planPreventiveVisit?.visitStatus?.id??0, textColor: AppColor.getRequestStatusTextColorByName(context, planPreventiveVisit.visitStatus!.name!), backgroundColor: AppColor.getRequestStatusColorByName(context, planPreventiveVisit.visitStatus!.name!), ), @@ -124,7 +125,7 @@ class _PpmDetailsPageState extends State { label: context.translation.viewDetails, ).paddingAll(16) ] - ]); + ]):const Center(child: NoDataFound()); }), ), ); diff --git a/lib/views/pages/device_transfer/device_transfer_details.dart b/lib/views/pages/device_transfer/device_transfer_details.dart index 80a04a9e..1359c203 100644 --- a/lib/views/pages/device_transfer/device_transfer_details.dart +++ b/lib/views/pages/device_transfer/device_transfer_details.dart @@ -13,6 +13,7 @@ import 'package:test_sa/views/pages/device_transfer/update_device_transfer.dart' import 'package:test_sa/views/widgets/images/files_list.dart'; import 'package:test_sa/views/widgets/loaders/app_loading.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; +import 'package:test_sa/views/widgets/loaders/no_data_found.dart'; import '../../../extensions/text_extensions.dart'; import '../../../models/enums/user_types.dart'; import '../../../new_views/app_style/app_color.dart'; @@ -57,131 +58,135 @@ class _DeviceTransferDetailsState extends State { } else { _model = snapshot.data as DeviceTransfer?; _attachments = _model?.assetTransferAttachments?.map((e) => File(e.attachmentName ?? '')).toList() ?? []; - return Form( - key: _formKey, - child: LoadingManager( - isLoading: _isLoading, - isFailedLoading: false, - stateCode: 200, - onRefresh: () async {}, - child: SingleChildScrollView( - child: Column( - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Text( - "Transfer Details".addTranslation, - style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), - ), - _buildTextWidget('${context.translation.requestNo} : ${_model?.transferCode ?? ""}'), - _buildTextWidget('${context.translation.transferType} : ${_model?.transferType?.name ?? ""}'), - _buildTextWidget('${context.translation.createdBy} : ${_model?.name ?? ""}'), - const Divider().defaultStyle(context), - Text( - "Asset Info".addTranslation, - style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), - ), - _buildTextWidget('${context.translation.assetName} : ${_model?.assetName?.cleanupWhitespace.capitalizeFirstOfEach ?? ""}'), - _buildTextWidget('${context.translation.assetNumber} : ${_model?.assetNumber ?? ""}'), - _buildTextWidget('${context.translation.model} : ${_model?.modelName ?? ""}'), - _buildTextWidget('${context.translation.sn} : ${_model?.assetSerialNo ?? ""}'), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _contactInfo(), - if ((_model?.comment ?? "").isNotEmpty) ...[ - const Divider().defaultStyle(context), + return _model != null + ? Form( + key: _formKey, + child: LoadingManager( + isLoading: _isLoading, + isFailedLoading: false, + stateCode: 200, + onRefresh: () async {}, + child: SingleChildScrollView( + child: Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ Text( - "Comments".addTranslation, + "Transfer Details".addTranslation, style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), ), - 8.height, - _buildTextWidget(_model!.comment!), - ], - if (_attachments.isNotEmpty) ...[ + _buildTextWidget('${context.translation.requestNo} : ${_model?.transferCode ?? ""}'), + _buildTextWidget('${context.translation.transferType} : ${_model?.transferType?.name ?? ""}'), + _buildTextWidget('${context.translation.createdBy} : ${_model?.name ?? ""}'), const Divider().defaultStyle(context), Text( - "Attachments".addTranslation, + "Asset Info".addTranslation, style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), ), - 8.height, - FilesList(images: _model?.assetTransferAttachments?.map((e) => URLs.getFileUrl(e.attachmentName ?? '') ?? '').toList() ?? []), - //attachmentWidget(), - ] - ], + _buildTextWidget('${context.translation.assetName} : ${_model?.assetName?.cleanupWhitespace.capitalizeFirstOfEach ?? ""}'), + _buildTextWidget('${context.translation.assetNumber} : ${_model?.assetNumber ?? ""}'), + _buildTextWidget('${context.translation.model} : ${_model?.modelName ?? ""}'), + _buildTextWidget('${context.translation.sn} : ${_model?.assetSerialNo ?? ""}'), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _contactInfo(), + if ((_model?.comment ?? "").isNotEmpty) ...[ + const Divider().defaultStyle(context), + Text( + "Comments".addTranslation, + style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), + ), + 8.height, + _buildTextWidget(_model!.comment!), + ], + if (_attachments.isNotEmpty) ...[ + const Divider().defaultStyle(context), + Text( + "Attachments".addTranslation, + style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), + ), + 8.height, + FilesList(images: _model?.assetTransferAttachments?.map((e) => URLs.getFileUrl(e.attachmentName ?? '') ?? '').toList() ?? []), + //attachmentWidget(), + ] + ], + ), + ], + ).expanded, + Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + 1.width, + Text( + _model?.createdOn != null ? _model!.createdOn!.toServiceRequestCardFormat : "", + textAlign: TextAlign.end, + style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20), + ), + ], + ), + ], + ).toShadowContainer(context), + 8.height, + if (_model?.transferType?.value == 1) ...[ + _internalRequestDetailsCard( + statusLabel: _model?.senderMachineStatusName != null + ? StatusLabel( + label: _model!.senderMachineStatusName!, + id: _model!.senderMachineStatusId!.toInt(), + textColor: AppColor.getRequestStatusTextColorByName(context, _model!.senderMachineStatusName!), + backgroundColor: AppColor.getRequestStatusColorByName(context, _model!.senderMachineStatusName!), + ) + : null, + ) + ] else ...[ + // sender card + _buildCard( + isSender: true, + site: _model?.senderSiteName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", + dept: _model?.senderDepartmentName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", + building: _model?.senderBuildingName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", + floor: _model?.senderFloorName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", + comment: _model?.senderComment ?? "", + statusLabel: _model?.senderMachineStatusName != null + ? StatusLabel( + label: _model!.senderMachineStatusName!, + id: _model!.senderMachineStatusId!.toInt(), + textColor: AppColor.getRequestStatusTextColorByName(context, _model!.senderMachineStatusName!), + backgroundColor: AppColor.getRequestStatusColorByName(context, _model!.senderMachineStatusName!), + ) + : null, ), - ], - ).expanded, - Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - 1.width, - Text( - _model?.createdOn != null ? _model!.createdOn!.toServiceRequestCardFormat : "", - textAlign: TextAlign.end, - style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20), + 8.height, + // receiver card + _buildCard( + isSender: false, + site: _model?.destSiteName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", + dept: _model?.destDepartmentName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", + building: _model?.destBuildingName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", + floor: _model?.destFloorName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", + comment: _model?.receiverComment ?? "", + statusLabel: _model?.receiverMachineStatusName != null + ? StatusLabel( + label: _model!.receiverMachineStatusName ?? "", + id: _model!.receiverMachineStatusId!.toInt(), + textColor: AppColor.getRequestStatusTextColorByName(context, _model!.receiverMachineStatusName!), + backgroundColor: AppColor.getRequestStatusColorByName(context, _model!.receiverMachineStatusName!)) + : null, ), ], - ), - ], - ).toShadowContainer(context), - 8.height, - if (_model?.transferType?.value == 1) ...[ - _internalRequestDetailsCard( - statusLabel: _model?.senderMachineStatusName != null - ? StatusLabel( - label: _model!.senderMachineStatusName!, - id: _model!.senderMachineStatusId!.toInt(), - textColor: AppColor.getRequestStatusTextColorByName(context, _model!.senderMachineStatusName!), - backgroundColor: AppColor.getRequestStatusColorByName(context, _model!.senderMachineStatusName!), - ) - : null, - ) - ] else ...[ - // sender card - _buildCard( - isSender: true, - site: _model?.senderSiteName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", - dept: _model?.senderDepartmentName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", - building: _model?.senderBuildingName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", - floor: _model?.senderFloorName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", - comment: _model?.senderComment ?? "", - statusLabel: _model?.senderMachineStatusName != null - ? StatusLabel( - label: _model!.senderMachineStatusName!, - id: _model!.senderMachineStatusId!.toInt(), - textColor: AppColor.getRequestStatusTextColorByName(context, _model!.senderMachineStatusName!), - backgroundColor: AppColor.getRequestStatusColorByName(context, _model!.senderMachineStatusName!), - ) - : null, - ), - 8.height, - // receiver card - _buildCard( - isSender: false, - site: _model?.destSiteName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", - dept: _model?.destDepartmentName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", - building: _model?.destBuildingName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", - floor: _model?.destFloorName?.cleanupWhitespace.capitalizeFirstOfEach ?? "", - comment: _model?.receiverComment ?? "", - statusLabel: _model?.receiverMachineStatusName != null - ? StatusLabel( - label: _model!.receiverMachineStatusName ?? "", - id: _model!.receiverMachineStatusId!.toInt(), - textColor: AppColor.getRequestStatusTextColorByName(context, _model!.receiverMachineStatusName!), - backgroundColor: AppColor.getRequestStatusColorByName(context, _model!.receiverMachineStatusName!)) - : null, - ), - ], - ], - ).paddingAll(16), - ), - ), - ); + ], + ).paddingAll(16), + ), + ), + ) + : const Center( + child: NoDataFound(), + ); } }, ), diff --git a/lib/views/widgets/requests/request_status.dart b/lib/views/widgets/requests/request_status.dart index 2f655bc3..b304eb51 100644 --- a/lib/views/widgets/requests/request_status.dart +++ b/lib/views/widgets/requests/request_status.dart @@ -4,7 +4,7 @@ import 'package:test_sa/extensions/text_extensions.dart'; class StatusLabel extends StatelessWidget { String? label; - final int id; + final int? id; final Color? backgroundColor; final Color? textColor; final bool isPriority;