From 300bc0a1a620508f918747b7e7c0a0f0dde5feb8 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Tue, 5 Sep 2023 12:24:30 +0300 Subject: [PATCH] improvements --- lib/models/pantry/pentry.dart | 14 +++++-- .../device_transfer_details.dart | 8 ++-- .../user/gas_refill/gas_refill_details.dart | 42 ++++++++++--------- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/lib/models/pantry/pentry.dart b/lib/models/pantry/pentry.dart index 57f871c1..606a73f1 100644 --- a/lib/models/pantry/pentry.dart +++ b/lib/models/pantry/pentry.dart @@ -87,7 +87,7 @@ class Pentry { map["workingHours"] = (timer.durationInSecond / 60 / 60).toStringAsFixed(5); } if (files?.isNotEmpty ?? false) { - map["vAttachments"] = files.map((file) => {"attachmentName": (file.path.split("/").last + base64Encode(file.readAsBytesSync()))}).toList(); + map["vAttachments"] = files.map((file) => {"attachmentName": _isLocalUrl(file.path) ? (file.path.split("/").last + "|" + base64Encode(file.readAsBytesSync())): file.path}).toList(); } map["travelingHours"] = travelingHours; // if(contacts?.isNotEmpty == true) { @@ -104,7 +104,10 @@ class Pentry { map["engSignature"] = signatureEngineer; //"${DateTime.now().toIso8601String()}.png|$signatureEngineer"; return map; } - + bool _isLocalUrl(String url) { + if (url?.isEmpty != false) return false; + return url.startsWith("/") || url.startsWith("file://") || url.substring(1).startsWith(':\\'); + } factory Pentry.fromMap(Map map) { // List contacts = []; // if(map['contacts'] != null){ @@ -120,6 +123,7 @@ class Pentry { List files = []; if (map["vAttachments"] != null) if (map["vAttachments"] is List) { List list = map["vAttachments"]; + list.removeWhere((element) => (element["attachmentURL"]?.toString() ?? "").isEmpty); files = list.map((e) => URLs.getFileUrl(e["attachmentName"])).toList(); } List ppmCheckLists = []; @@ -146,7 +150,11 @@ class Pentry { ppmCheckLists: ppmCheckLists, calibrationTools: calibrationTools, pmKits: pmKits, - files: files.map((e) => File(e)).toList(), + files: files?.map((e) { + print("${map["id"]}:${files?.length}:e:$e"); + return File(e); + })?.toList() ?? + [], signatureNurse: URLs.getFileUrl(map["nurseSignature"]), signatureEngineer: URLs.getFileUrl(map["engSignature"]), ); diff --git a/lib/views/pages/device_transfer/device_transfer_details.dart b/lib/views/pages/device_transfer/device_transfer_details.dart index 2e807ec9..82d65dba 100644 --- a/lib/views/pages/device_transfer/device_transfer_details.dart +++ b/lib/views/pages/device_transfer/device_transfer_details.dart @@ -144,13 +144,13 @@ class _DeviceTransferDetailsState extends State { ASmallButton( text: _subtitle.edit, onPressed: (_isSender) - ? () { + ? ( _model.sender.status?.name=="Closed" ? null: () { Navigator.of(context).push(MaterialPageRoute( builder: (_) => UpdateDeviceTransfer( model: _model, isSender: true, ))); - } + }) : null, ), ], @@ -170,13 +170,13 @@ class _DeviceTransferDetailsState extends State { ASmallButton( text: _subtitle.edit, onPressed: (_isReceiver) - ? () { + ? ( _model.receiver.status?.name=="Closed" ? null: () { Navigator.of(context).push(MaterialPageRoute( builder: (_) => UpdateDeviceTransfer( model: _model, isSender: false, ))); - } + }) : null, ), ], 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 589c9094..9a98b8d0 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -121,26 +121,28 @@ class _GasRefillDetailsState extends State { color: Theme.of(context).colorScheme.onPrimary, buttonSize: 42, backgroundColor: AColors.green, - onPressed: () async { - // _enableEdit = !_enableEdit; - print(widget.model.startDate); - _model?.fromGasRefillModel(widget.model); - print(widget.model.startDate); - // setState(() {}); - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => RequestGasRefill( - gasRefillModel: widget.model, - ), - ), - ).then((value) { - if (value != null) { - _model = value; - } - }); - setState(() {}); - }, + onPressed: (widget.model.status?.value ?? 0) == 2 + ? null + : () async { + // _enableEdit = !_enableEdit; + print(widget.model.startDate); + _model?.fromGasRefillModel(widget.model); + print(widget.model.startDate); + // setState(() {}); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => RequestGasRefill( + gasRefillModel: widget.model, + ), + ), + ).then((value) { + if (value != null) { + _model = value; + } + }); + setState(() {}); + }, ), const SizedBox( width: 16,