From 9dca07012153ef043b7cf21928bd36c11a777f41 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Thu, 7 Sep 2023 11:33:40 +0300 Subject: [PATCH] add asset id to spare parts API add attachments and signature to the sender & receiver info --- .../api/device_transfer_provider.dart | 36 ++- .../providers/api/parts_provider.dart | 6 +- lib/models/device/device_transfer.dart | 20 +- lib/models/device/device_transfer_info.dart | 59 ++--- .../update_device_transfer.dart | 17 +- .../create_sub_workorder_page.dart | 4 +- .../spare_parts_details_bottom_sheet.dart | 1 + .../report/create_service_report.dart | 1 + .../requests/report/edit_service_report.dart | 1 + .../pages/user/visits/pantry/edit_pentry.dart | 1 + .../device_transfer_info_section.dart | 20 +- .../widgets/images/multi_image_picker.dart | 208 +++++++++--------- .../images/multi_image_picker_item.dart | 39 ++-- .../parts/auto_complete_parts_field.dart | 5 +- .../widgets/pentry/pentry_pm_kit_form.dart | 3 + 15 files changed, 243 insertions(+), 178 deletions(-) diff --git a/lib/controllers/providers/api/device_transfer_provider.dart b/lib/controllers/providers/api/device_transfer_provider.dart index 1b77c7ba..52434818 100644 --- a/lib/controllers/providers/api/device_transfer_provider.dart +++ b/lib/controllers/providers/api/device_transfer_provider.dart @@ -140,6 +140,9 @@ class DeviceTransferProvider extends ChangeNotifier { "senderFloorId": model.device.destFloorId, "senderDepartmentId": model.device.destDepartmentId, "senderRoom": model.device.destRoom, + if (model?.sender?.attachments?.isNotEmpty ?? false) + "senderAttachments": + model?.sender?.attachments?.map((file) => {"attachmentName": _isLocalUrl(file.path) ? ("${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}") : file.path})?.toList(), // "senderAssignedEmployeeId": "string", // "senderMachineStatusId": 0, // "senderComment": "string", @@ -202,7 +205,10 @@ class DeviceTransferProvider extends ChangeNotifier { "senderStartDate": newModel.timer?.startAt?.toIso8601String(), "senderEndDate": newModel.timer?.endAt?.toIso8601String(), "senderTravelingHours": newModel.travelingHours, - "senderAttachmentName": newModel?.signature ?? "", + "senderEngSignature": newModel.engSignature, + if (newModel?.attachments?.isNotEmpty ?? false) + "senderAttachments": + newModel?.attachments?.map((file) => {"attachmentName": _isLocalUrl(file.path) ? ("${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}") : file.path})?.toList(), "destSiteId": oldModel.receiver.client?.id, "destDepartmentId": oldModel.receiver.department?.id, "destBuildingId": oldModel.device?.destBuildingId, @@ -214,8 +220,12 @@ class DeviceTransferProvider extends ChangeNotifier { "receiverWorkingHours": oldModel.receiver.workingHours, "receiverStartDate": oldModel.receiver.timer?.startAt?.toIso8601String(), "receiverEndDate": oldModel.receiver.timer?.endAt?.toIso8601String(), - "receiverTravelingHours": oldModel.receiver.travelingHours, - "receiverAttachmentName": oldModel.receiver?.signature ?? "", + "receiverTravelingHours": oldModel.receiver?.travelingHours, + "receiverEngSignature": oldModel.receiver?.engSignature, + if (oldModel.receiver?.attachments?.isNotEmpty ?? false) + "receiverAttachments": oldModel.receiver?.attachments + ?.map((file) => {"attachmentName": _isLocalUrl(file.path) ? ("${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}") : file.path}) + ?.toList(), }); } else { body.addAll({ @@ -227,8 +237,11 @@ class DeviceTransferProvider extends ChangeNotifier { "senderWorkingHours": oldModel.sender.workingHours, "senderStartDate": oldModel.sender.timer?.startAt?.toIso8601String(), "senderEndDate": oldModel.sender.timer?.endAt?.toIso8601String(), - "senderTravelingHours": oldModel.sender.travelingHours, - "senderAttachmentName": oldModel.sender?.signature ?? "", + "senderTravelingHours": oldModel.sender?.travelingHours, + "senderEngSignature": oldModel.sender?.engSignature, + if (oldModel.sender?.attachments?.isNotEmpty ?? false) + "senderAttachments": + oldModel.sender?.attachments?.map((file) => {"attachmentName": _isLocalUrl(file.path) ? ("${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}") : file.path})?.toList(), "destSiteId": newModel.client?.id, "destDepartmentId": newModel.department?.id, "destBuildingId": oldModel.device?.destBuildingId, @@ -241,10 +254,12 @@ class DeviceTransferProvider extends ChangeNotifier { "receiverStartDate": newModel.timer?.startAt?.toIso8601String(), "receiverEndDate": newModel.timer?.endAt?.toIso8601String(), "receiverTravelingHours": newModel.travelingHours, - "receiverAttachmentName": newModel?.signature ?? "", + "receiverEngSignature": newModel.engSignature, + if (newModel?.attachments?.isNotEmpty ?? false) + "receiverAttachments": + newModel?.attachments?.map((file) => {"attachmentName": _isLocalUrl(file.path) ? ("${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}") : file.path})?.toList(), }); } - if (true) {} //body.addAll(newModel.toJson(isSender)); log(body?.toString()); Response response; @@ -252,7 +267,7 @@ class DeviceTransferProvider extends ChangeNotifier { response = await ApiManager.instance.put(URLs.updateDeviceTransfer, body: body); print(response.body); - print("${newModel.signature}.png"); + print("${newModel.engSignature}.png"); // response = await post( // Uri.parse("$host${URLs.updateDeviceTransfer}/$requestId"), // body: body, @@ -273,4 +288,9 @@ class DeviceTransferProvider extends ChangeNotifier { return -1; } } + + bool _isLocalUrl(String url) { + if (url?.isEmpty != false) return false; + return url.startsWith("/") || url.startsWith("file://") || url.substring(1).startsWith(':\\'); + } } diff --git a/lib/controllers/providers/api/parts_provider.dart b/lib/controllers/providers/api/parts_provider.dart index fbe7a319..de14ce42 100644 --- a/lib/controllers/providers/api/parts_provider.dart +++ b/lib/controllers/providers/api/parts_provider.dart @@ -90,13 +90,13 @@ class PartsProvider extends ChangeNotifier { /// return state code if request complete may be 200, 404 or 403 /// for more details check http state manager /// lib\controllers\http_status_manger\http_status_manger.dart - Future> getPartsList({String host, User user, String title}) async { + Future> getPartsList({String host, User user, num assetId, String title}) async { Response response; try { if (int.tryParse(title) != null) { - response = await ApiManager.instance.post(URLs.getPartNumber, body: {if (title != null && title.isNotEmpty) "partNo": title}); + response = await ApiManager.instance.post(URLs.getPartNumber, body: {if (title != null && title.isNotEmpty) "partNo": title, "assetId": assetId}); } else { - response = await ApiManager.instance.post(URLs.getPartNumber, body: {if (title != null && title.isNotEmpty) "partName": title}); + response = await ApiManager.instance.post(URLs.getPartNumber, body: {if (title != null && title.isNotEmpty) "partName": title, "assetId": assetId}); } List page = []; if (response.statusCode >= 200 && response.statusCode < 300) { diff --git a/lib/models/device/device_transfer.dart b/lib/models/device/device_transfer.dart index 3c41746a..75e9ef75 100644 --- a/lib/models/device/device_transfer.dart +++ b/lib/models/device/device_transfer.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/models/department.dart'; import 'package:test_sa/models/device/device.dart'; @@ -46,6 +48,16 @@ class DeviceTransfer { } factory DeviceTransfer.fromJson(Map parsedJson) { + List senderFiles = []; + if (parsedJson["senderAttachments"] != null && parsedJson["senderAttachments"] is List) { + List list = parsedJson["senderAttachments"]; + senderFiles = list.map((e) => (URLs.getFileUrl(e["attachmentName"]))).toList(); + } + List receiverFiles = []; + if (parsedJson["receiverAttachments"] != null && parsedJson["receiverAttachments"] is List) { + List list = parsedJson["receiverAttachments"]; + receiverFiles = list.map((e) => (URLs.getFileUrl(e["attachmentName"]))).toList(); + } return DeviceTransfer( id: parsedJson["id"], title: parsedJson["transferCode"], @@ -69,6 +81,7 @@ class DeviceTransfer { travelingHours: parsedJson["senderTravelingHours"], comment: parsedJson["senderComment"], workingHours: parsedJson["senderWorkingHours"], + attachments: senderFiles?.map((e) => File(e))?.toList(), timer: TimerModel( startAt: DateTime.tryParse(parsedJson["senderStartDate"] ?? ""), endAt: DateTime.tryParse(parsedJson["senderEndDate"] ?? ""), @@ -84,8 +97,7 @@ class DeviceTransfer { id: parsedJson["senderDepartmentId"], name: parsedJson["senderDepartmentName"], ), - // todo add segnature - signature: URLs.getFileUrl(parsedJson["senderAttachmentName"]), + engSignature: URLs.getFileUrl(parsedJson["senderEngSignature"]), status: Lookup( id: parsedJson["senderMachineStatusId"], name: parsedJson["senderMachineStatusName"], @@ -95,6 +107,7 @@ class DeviceTransfer { travelingHours: parsedJson["receiverTravelingHours"], comment: parsedJson["receiverComment"], workingHours: parsedJson["receiverWorkingHours"], + attachments: receiverFiles?.map((e) => File(e))?.toList(), timer: parsedJson["receiverStartDate"] != null || parsedJson["receiverEndDate"] != null ? TimerModel(startAt: DateTime.tryParse(parsedJson["receiverStartDate"] ?? ""), endAt: DateTime.tryParse(parsedJson["receiverEndDate"] ?? "")) : null, @@ -108,8 +121,7 @@ class DeviceTransfer { id: parsedJson["destDepartmentId"], name: parsedJson["destDepartmentName"], ), - // todo add segnature - signature: URLs.getFileUrl(parsedJson["receiverAttachmentName"]), + engSignature: URLs.getFileUrl(parsedJson["receiverEngSignature"]), status: Lookup( id: parsedJson["receiverMachineStatusId"], name: parsedJson["receiverMachineStatusName"], diff --git a/lib/models/device/device_transfer_info.dart b/lib/models/device/device_transfer_info.dart index 904b033e..ef03cd1b 100644 --- a/lib/models/device/device_transfer_info.dart +++ b/lib/models/device/device_transfer_info.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:test_sa/models/department.dart'; import 'package:test_sa/models/hospital.dart'; import 'package:test_sa/models/lookup.dart'; @@ -15,7 +17,8 @@ class DeviceTransferInfo { // DateTime endDate; String travelingHours; String userName; - String signature; + String engSignature; + List attachments; String assignedEmployeeName; Lookup status; TimerModel timer; @@ -30,10 +33,11 @@ class DeviceTransferInfo { // this.startDate, // this.endDate, this.workingHours, - this.signature, + this.engSignature, this.status, this.assignedEmployeeName, this.timer, + this.attachments, }); Map toJson(bool isSender) { @@ -48,7 +52,7 @@ class DeviceTransferInfo { if (timer?.endAt != null) body["${baseKey}end_date"] = timer?.endAt?.toIso8601String(); if (travelingHours != null && travelingHours.isNotEmpty) body["${baseKey}travel_hours"] = travelingHours; if (status != null) body["${baseKey}status"] = status.id.toString(); - if (signature != null && signature.isNotEmpty) body["${baseKey}image"] = signature; + if (engSignature != null && engSignature.isNotEmpty) body["${baseKey}image"] = engSignature; return body; } @@ -64,36 +68,37 @@ class DeviceTransferInfo { client = Hospital.fromHospital(old.client); department = Department.fromDepartment(old.department); workingHours = old.workingHours; + attachments = old.attachments ?? []; // startDate = old.startDate; // endDate = old.endDate; timer = old.timer; travelingHours = old.travelingHours; comment = old.comment; - if (withSignature) signature = old.signature; + if (withSignature) engSignature = old.engSignature; status = old.status; } - factory DeviceTransferInfo.fromJson(Map parsedJson, String key) { - return DeviceTransferInfo( - workingHours: parsedJson["${key}working_hours"], - // startDate: parsedJson["${key}start_date"], - // endDate: parsedJson["${key}end_date"], - timer: TimerModel( - startAt: DateTime.tryParse(parsedJson["${key}start_date"] ?? ""), - endAt: DateTime.tryParse(parsedJson["${key}end_date"] ?? ""), - durationInSecond: ((parsedJson["${key}working_hours"] ?? 0) * 60 * 60).toInt(), - ), - travelingHours: parsedJson["${key}travel_hours"], - userName: parsedJson["${key}name"], - signature: parsedJson["${key}image"], - userId: parsedJson["${key}id"], - comment: parsedJson["${key}comment"], - assignedEmployeeName: parsedJson["${key}AssignedEmployeeName"], - client: Hospital(id: parsedJson["${key}SiteId"], name: parsedJson["${key}SiteName"]), - department: Department( - id: parsedJson["${key}DepartmentId"], - name: parsedJson["${key}DepartmentName"], - ), - ); - } + // factory DeviceTransferInfo.fromJson(Map parsedJson, String key) { + // return DeviceTransferInfo( + // workingHours: parsedJson["${key}working_hours"], + // // startDate: parsedJson["${key}start_date"], + // // endDate: parsedJson["${key}end_date"], + // timer: TimerModel( + // startAt: DateTime.tryParse(parsedJson["${key}start_date"] ?? ""), + // endAt: DateTime.tryParse(parsedJson["${key}end_date"] ?? ""), + // durationInSecond: ((parsedJson["${key}working_hours"] ?? 0) * 60 * 60).toInt(), + // ), + // travelingHours: parsedJson["${key}travel_hours"], + // userName: parsedJson["${key}name"], + // signature: parsedJson["${key}image"], + // userId: parsedJson["${key}id"], + // comment: parsedJson["${key}comment"], + // assignedEmployeeName: parsedJson["${key}AssignedEmployeeName"], + // client: Hospital(id: parsedJson["${key}SiteId"], name: parsedJson["${key}SiteName"]), + // department: Department( + // id: parsedJson["${key}DepartmentId"], + // name: parsedJson["${key}DepartmentName"], + // ), + // ); + // } } diff --git a/lib/views/pages/device_transfer/update_device_transfer.dart b/lib/views/pages/device_transfer/update_device_transfer.dart index 36a9c78e..29844f8a 100644 --- a/lib/views/pages/device_transfer/update_device_transfer.dart +++ b/lib/views/pages/device_transfer/update_device_transfer.dart @@ -14,9 +14,9 @@ import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/widgets/app_text_form_field.dart'; import 'package:test_sa/views/widgets/buttons/app_button.dart'; import 'package:test_sa/views/widgets/e_signature/e_signature.dart'; +import 'package:test_sa/views/widgets/images/multi_image_picker.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; import 'package:test_sa/views/widgets/status/asset_status.dart'; -import 'package:test_sa/views/widgets/status/gas_refill/gas_status.dart'; import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; import '../../../../controllers/localization/localization.dart'; @@ -41,7 +41,7 @@ class _UpdateDeviceTransferState extends State { Uint8List _signature; DeviceTransferProvider _deviceTransferProvider; final TextEditingController _requestedQuantityController = TextEditingController(); - final DeviceTransferInfo _formModel = DeviceTransferInfo(); + final DeviceTransferInfo _formModel = DeviceTransferInfo(attachments: []); final GlobalKey _formKey = GlobalKey(); final GlobalKey _scaffoldKey = GlobalKey(); @@ -189,7 +189,14 @@ class _UpdateDeviceTransferState extends State { }, ), const SizedBox( - height: 8, + height: 16, + ), + MultiFilesPicker( + label: "Attachments", + files: _formModel.attachments, + ), + const SizedBox( + height: 16, ), const ASubTitle("Signature"), // if(_validate && _formModel.signature == null) @@ -198,12 +205,12 @@ class _UpdateDeviceTransferState extends State { height: 4, ), ESignature( - oldSignature: widget.isSender ? widget.model.sender.signature : widget.model.receiver.signature, + oldSignature: widget.isSender ? widget.model.sender.engSignature : widget.model.receiver.engSignature, newSignature: _signature, onSaved: (signature) { _signature = signature; if (signature == null || signature.isEmpty) return; - _formModel.signature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + _formModel.engSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; // base64Encode(signature); }, ), diff --git a/lib/views/pages/sub_workorder/create_sub_workorder_page.dart b/lib/views/pages/sub_workorder/create_sub_workorder_page.dart index 9a6f36db..87bf05db 100644 --- a/lib/views/pages/sub_workorder/create_sub_workorder_page.dart +++ b/lib/views/pages/sub_workorder/create_sub_workorder_page.dart @@ -55,7 +55,7 @@ class _CreateSubWorkOrderPageState extends State { void initState() { _subWorkOrders = SearchWorkOrder( assignedEmployee: widget?.workOrder?.callRequest?.assignedEmployee, - callRequest: CallRequest(id: widget?.workOrder?.callRequest?.id), + callRequest: CallRequest(id: widget?.workOrder?.callRequest?.id, asset: widget.workOrder?.callRequest?.asset), currentSituation: null, supplier: null, parentWOId: widget.workOrder.id, @@ -328,7 +328,7 @@ class _CreateSubWorkOrderPageState extends State { _validate = true; setState(() {}); if (validate()) { - if(_subWorkOrders.calllastSituation.value == 12 && (_subWorkOrders.sparePartsWorkOrders == null || _subWorkOrders.sparePartsWorkOrders.isEmpty)){ + if (_subWorkOrders.calllastSituation.value == 12 && (_subWorkOrders.sparePartsWorkOrders == null || _subWorkOrders.sparePartsWorkOrders.isEmpty)) { await Fluttertoast.showToast(msg: "You have to add parts"); return; } diff --git a/lib/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart b/lib/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart index d8d47e5c..96b2e276 100644 --- a/lib/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart +++ b/lib/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart @@ -97,6 +97,7 @@ class _SparePartsBottomSheetState extends State { : const SizedBox.shrink(), const SizedBox(height: 4), AutoCompletePartsField( + assetId: widget.subWorkOrder?.callRequest?.asset?.id, onPick: (part) { _workOrder.sparePartsWorkOrders ??= []; _workOrder.sparePartsWorkOrders.add(SparePartsWorkOrders( diff --git a/lib/views/pages/user/requests/report/create_service_report.dart b/lib/views/pages/user/requests/report/create_service_report.dart index 374c305c..25a6bb24 100644 --- a/lib/views/pages/user/requests/report/create_service_report.dart +++ b/lib/views/pages/user/requests/report/create_service_report.dart @@ -873,6 +873,7 @@ class _CreateServiceReportState extends State with TickerPr height: 4, ), AutoCompletePartsField( + assetId: _serviceReport?.device?.id, onPick: (part) { _serviceReport.parts.add(part); }, diff --git a/lib/views/pages/user/requests/report/edit_service_report.dart b/lib/views/pages/user/requests/report/edit_service_report.dart index 7cc3fc01..ae74092f 100644 --- a/lib/views/pages/user/requests/report/edit_service_report.dart +++ b/lib/views/pages/user/requests/report/edit_service_report.dart @@ -1013,6 +1013,7 @@ class _EditServiceReportState extends State with TickerProvid height: 4, ), AutoCompletePartsField( + assetId: _serviceReport?.device?.id, onPick: (part) { _serviceReport.parts.add(part); setState(() {}); diff --git a/lib/views/pages/user/visits/pantry/edit_pentry.dart b/lib/views/pages/user/visits/pantry/edit_pentry.dart index 1873e8a0..a27b8308 100644 --- a/lib/views/pages/user/visits/pantry/edit_pentry.dart +++ b/lib/views/pages/user/visits/pantry/edit_pentry.dart @@ -146,6 +146,7 @@ class _EditPentryState extends State with SingleTickerProviderStateM PentryPMKitForm( models: _pentry.pmKits, enableValidate: _validate, + assetId: widget.visit?.deviceId, ), PentryInfoForm( model: _pentry, diff --git a/lib/views/widgets/device_trancfer/device_transfer_info_section.dart b/lib/views/widgets/device_trancfer/device_transfer_info_section.dart index 3bea8ba9..c5edceed 100644 --- a/lib/views/widgets/device_trancfer/device_transfer_info_section.dart +++ b/lib/views/widgets/device_trancfer/device_transfer_info_section.dart @@ -8,6 +8,7 @@ import 'package:test_sa/views/widgets/requests/info_row.dart'; import 'package:test_sa/views/widgets/requests/request_status.dart'; import '../../../controllers/providers/api/user_provider.dart'; +import '../images/multi_image_picker.dart'; class DeviceTransferInfoSection extends StatelessWidget { final DeviceTransferInfo info; @@ -19,7 +20,8 @@ class DeviceTransferInfoSection extends StatelessWidget { Widget build(BuildContext context) { info.userName = Provider.of(context).user.username; final subtitle = AppLocalization.of(context).subtitle; - print("url:${info.signature}"); + print("url:${info.engSignature}"); + info.attachments ??= []; return Column( children: [ RequestInfoRow( @@ -52,12 +54,16 @@ class DeviceTransferInfoSection extends StatelessWidget { ), RequestInfoRow( title: "Signature", - info: info.signature?.isEmpty != false ? subtitle.noDateFound : null, - contentWidget: info.signature?.isEmpty != false - ? null - : ImageLoader( - url: info.signature, - ), + info: info.engSignature?.isEmpty != false ? subtitle.noDateFound : null, + contentWidget: info.engSignature?.isEmpty != false ? null : ImageLoader(url: info.engSignature), + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 16), + child: MultiFilesPicker( + label: "Attachments", + files: info.attachments, + enabled: false, + ), ), RequestInfoRow( title: subtitle.status, diff --git a/lib/views/widgets/images/multi_image_picker.dart b/lib/views/widgets/images/multi_image_picker.dart index a19d3d56..aa3bfefc 100644 --- a/lib/views/widgets/images/multi_image_picker.dart +++ b/lib/views/widgets/images/multi_image_picker.dart @@ -33,117 +33,121 @@ class _MultiFilesPickerState extends State with TickerProvider Widget build(BuildContext context) { _size = MediaQuery.of(context).size; Subtitle subtitle = AppLocalization.of(context).subtitle; - return Container( - padding: const EdgeInsets.all(12), - decoration: BoxDecoration( - color: const Color(0xfff5f5f5), - border: Border.all( - color: const Color(0xffefefef), - ), - borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // SizedBox(height: 8 * AppStyle.getScaleFactor(context),), - Row( - children: [ - Expanded( - child: Text( - widget.label ?? subtitle.images, - style: Theme.of(context).textTheme.headline6.copyWith( - fontSize: 14, - ), - textScaleFactor: AppStyle.getScaleFactor(context), - ), + return (widget.enabled == false && (widget.files?.isEmpty ?? false)) + ? const SizedBox() + : Container( + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: const Color(0xfff5f5f5), + border: Border.all( + color: const Color(0xffefefef), ), - AFlatButton( - text: subtitle.add, - onPressed: widget.enabled - ? () { - // onImagePick(_subtitle); - onFilePicker(subtitle); - } - : null, - ), - ], - ), - 12.height, - AnimatedSize( - duration: const Duration(milliseconds: 400), - child: !widget.error - ? const SizedBox.shrink() - : Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - subtitle.imagesRequired, + borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // SizedBox(height: 8 * AppStyle.getScaleFactor(context),), + Row( + children: [ + Expanded( + child: Text( + widget.label ?? subtitle.images, style: Theme.of(context).textTheme.headline6.copyWith( fontSize: 14, - color: AColors.red, ), textScaleFactor: AppStyle.getScaleFactor(context), ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), + ), + if (widget.enabled) + AFlatButton( + text: subtitle.add, + onPressed: widget.enabled + ? () { + // onImagePick(_subtitle); + onFilePicker(subtitle); + } + : null, ), - ], - ), - ), - AnimatedSwitcher( - duration: const Duration(milliseconds: 400), - child: Container( - key: ValueKey(widget.files.length), - width: _size.width, - height: 200 * AppStyle.getScaleFactor(context), - padding: EdgeInsets.all( - 8 * AppStyle.getScaleFactor(context), - ), - alignment: Alignment.topLeft, - decoration: BoxDecoration( - border: Border.all(color: Theme.of(context).primaryColor, width: 2), - borderRadius: BorderRadius.circular(8 * AppStyle.getScaleFactor(context)), - ), - child: widget.files.isEmpty - ? MaterialButton( - onPressed: widget.enabled - ? () { - // onImagePick(_subtitle); - onFilePicker(subtitle); - } - : null, - child: Center( - child: Icon( - Icons.file_upload, - size: 48 * AppStyle.getScaleFactor(context), - color: Theme.of(context).primaryColor, - )), - ) - : GridView.count( - crossAxisCount: 2, - //_size.width ~/ 80, - scrollDirection: Axis.horizontal, - mainAxisSpacing: 10, - crossAxisSpacing: 10, - children: List.generate(widget.files.length, (index) { - File _image = widget.files[index]; - return MultiFilesPickerItem( - file: _image, - onRemoveTap: (image) { - if (!widget.enabled) { - return; - } - widget.files.remove(image); - setState(() {}); - }, - ); - }), + ], + ), + 12.height, + AnimatedSize( + duration: const Duration(milliseconds: 400), + child: !widget.error + ? const SizedBox.shrink() + : Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + subtitle.imagesRequired, + style: Theme.of(context).textTheme.headline6.copyWith( + fontSize: 14, + color: AColors.red, + ), + textScaleFactor: AppStyle.getScaleFactor(context), + ), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + ], + ), + ), + AnimatedSwitcher( + duration: const Duration(milliseconds: 400), + child: Container( + key: ValueKey(widget.files.length), + width: _size.width, + height: 200 * AppStyle.getScaleFactor(context), + padding: EdgeInsets.all( + 8 * AppStyle.getScaleFactor(context), + ), + alignment: Alignment.topLeft, + decoration: BoxDecoration( + border: Border.all(color: Theme.of(context).primaryColor, width: 2), + borderRadius: BorderRadius.circular(8 * AppStyle.getScaleFactor(context)), ), + child: widget.files.isEmpty && widget.enabled + ? MaterialButton( + onPressed: widget.enabled + ? () { + // onImagePick(_subtitle); + onFilePicker(subtitle); + } + : null, + child: Center( + child: Icon( + Icons.file_upload, + size: 48 * AppStyle.getScaleFactor(context), + color: Theme.of(context).primaryColor, + )), + ) + : GridView.count( + crossAxisCount: 2, + //_size.width ~/ 80, + scrollDirection: Axis.horizontal, + mainAxisSpacing: 10, + crossAxisSpacing: 10, + children: List.generate(widget.files.length, (index) { + File _image = widget.files[index]; + return MultiFilesPickerItem( + file: _image, + enabled: widget.enabled, + onRemoveTap: (image) { + if (!widget.enabled) { + return; + } + widget.files.remove(image); + setState(() {}); + }, + ); + }), + ), + ), + ), + ], ), - ), - ], - ), - ); + ); } fromFilePicker(Subtitle subtitle) async { diff --git a/lib/views/widgets/images/multi_image_picker_item.dart b/lib/views/widgets/images/multi_image_picker_item.dart index d5b00011..907c20fa 100644 --- a/lib/views/widgets/images/multi_image_picker_item.dart +++ b/lib/views/widgets/images/multi_image_picker_item.dart @@ -12,9 +12,10 @@ import 'package:url_launcher/url_launcher.dart'; class MultiFilesPickerItem extends StatelessWidget { final File file; + final bool enabled; final Function(File) onRemoveTap; - const MultiFilesPickerItem({Key key, this.file, this.onRemoveTap}) : super(key: key); + const MultiFilesPickerItem({Key key, this.file, this.enabled, this.onRemoveTap}) : super(key: key); @override Widget build(BuildContext context) { @@ -68,23 +69,25 @@ class MultiFilesPickerItem extends StatelessWidget { } } }, - child: Align( - alignment: Alignment.topRight, - child: IconButton( - padding: const EdgeInsets.all(2.0), - icon: Container( - padding: const EdgeInsets.all(1), - decoration: BoxDecoration(color: Theme.of(context).scaffoldBackgroundColor.withOpacity(.3), borderRadius: BorderRadius.circular(8)), - child: const Icon( - Icons.remove_circle, - color: AColors.red, - ), - ), - onPressed: () { - onRemoveTap(file); - }, - ), - ), + child: enabled + ? Align( + alignment: Alignment.topRight, + child: IconButton( + padding: const EdgeInsets.all(2.0), + icon: Container( + padding: const EdgeInsets.all(1), + decoration: BoxDecoration(color: Theme.of(context).scaffoldBackgroundColor.withOpacity(.3), borderRadius: BorderRadius.circular(8)), + child: const Icon( + Icons.remove_circle, + color: AColors.red, + ), + ), + onPressed: () { + onRemoveTap(file); + }, + ), + ) + : const SizedBox(), ), ); } diff --git a/lib/views/widgets/parts/auto_complete_parts_field.dart b/lib/views/widgets/parts/auto_complete_parts_field.dart index a64bb56a..71bf0098 100644 --- a/lib/views/widgets/parts/auto_complete_parts_field.dart +++ b/lib/views/widgets/parts/auto_complete_parts_field.dart @@ -10,10 +10,11 @@ import 'package:test_sa/views/app_style/sizing.dart'; class AutoCompletePartsField extends StatefulWidget { final String initialValue; + final num assetId; final bool clearAfterPick; final Function(Part) onPick; - const AutoCompletePartsField({Key key, this.initialValue, this.onPick, this.clearAfterPick = true}) : super(key: key); + const AutoCompletePartsField({Key key, this.initialValue, this.assetId, this.onPick, this.clearAfterPick = true}) : super(key: key); @override _AutoCompletePartsFieldState createState() => _AutoCompletePartsFieldState(); @@ -64,7 +65,7 @@ class _AutoCompletePartsFieldState extends State { textInputAction: TextInputAction.search, ), suggestionsCallback: (vale) async { - return await _partsProvider.getPartsList(host: _settingProvider.host, title: vale); + return await _partsProvider.getPartsList(host: _settingProvider.host, title: vale, assetId: widget.assetId); }, itemBuilder: (context, part) { return ListTile( diff --git a/lib/views/widgets/pentry/pentry_pm_kit_form.dart b/lib/views/widgets/pentry/pentry_pm_kit_form.dart index f072bc84..2f83c8fa 100644 --- a/lib/views/widgets/pentry/pentry_pm_kit_form.dart +++ b/lib/views/widgets/pentry/pentry_pm_kit_form.dart @@ -11,9 +11,11 @@ import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; class PentryPMKitForm extends StatefulWidget { final List models; final bool enableValidate; + final num assetId; const PentryPMKitForm({ Key key, this.models, + this.assetId, this.enableValidate, }) : super(key: key); @@ -71,6 +73,7 @@ class _PentryPMKitFormState extends State { height: 4, ), AutoCompletePartsField( + assetId: widget.assetId, clearAfterPick: false, initialValue: (model.itemCode?.name ?? "").toString(), onPick: (part) {