From f6e1f5b66a6f016a29471b34a5a756d5bd84cb0b Mon Sep 17 00:00:00 2001 From: Andrea Antonello Date: Mon, 2 Dec 2024 09:41:50 +0100 Subject: [PATCH] better view of encoded values --- .../flutterlibs/forms/form_item_widgets.dart | 57 +++++++++++++++---- .../flutterlibs/forms/forms_widgets.dart | 28 +++++---- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/lib/com/hydrologis/flutterlibs/forms/form_item_widgets.dart b/lib/com/hydrologis/flutterlibs/forms/form_item_widgets.dart index 0930173..46806d4 100644 --- a/lib/com/hydrologis/flutterlibs/forms/form_item_widgets.dart +++ b/lib/com/hydrologis/flutterlibs/forms/form_item_widgets.dart @@ -78,7 +78,39 @@ abstract class AFormWidget { } static Widget getSimpleLabelValue( - String label, String value, PresentationMode pm) { + String label, SmashFormItem item, PresentationMode pm, + {String? forceValue}) { + dynamic value = forceValue; + if (value == null) { + value = item.value; + if (value == null) { + return Container(); + } else if (value is List && value.isEmpty) { + return Container(); + } + // if value has a label in the map, use it + List valueLabels = []; + if (item.map["values"] != null && + item.map["values"]?["items"] != null && + item.map["values"]?["items"] is List) { + for (var listItem in item.map["values"]?["items"]) { + var itemMap = listItem["item"]; + var itemLabel = itemMap?["label"]; + var itemValue = itemMap?["value"]; + if (itemLabel == null || itemValue == null) { + continue; + } + if (itemValue == value || + (value is List && value.contains(itemValue))) { + valueLabels.add(itemLabel); + } + } + } + if (valueLabels.isNotEmpty) { + value = valueLabels.join(", "); + } + } + Widget field; if (pm.detailMode == DetailMode.NORMAL) { field = Column( @@ -89,7 +121,7 @@ abstract class AFormWidget { color: pm.labelTextColor, bold: pm.doLabelBold), Padding( padding: const EdgeInsets.only(left: 12.0, top: 8), - child: SmashUI.normalText(value, + child: SmashUI.normalText(value.toString(), color: pm.valueTextColor, bold: pm.doValueBold), ), ], @@ -103,7 +135,7 @@ abstract class AFormWidget { color: pm.labelTextColor, bold: pm.doLabelBold), Padding( padding: const EdgeInsets.only(left: 12.0), - child: SmashUI.normalText(value, + child: SmashUI.normalText(value.toString(), color: pm.valueTextColor, bold: pm.doValueBold), ), ], @@ -718,8 +750,8 @@ class DateWidget extends AFormWidget { if (itemReadonly && presentationMode.detailMode != DetailMode.DETAILED) { widget = ListTile( leading: icon, - title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + title: + AFormWidget.getSimpleLabelValue(label, formItem, presentationMode), ); } else { widget = ListTile( @@ -786,8 +818,8 @@ class TimeWidget extends AFormWidget { if (itemReadonly && presentationMode.detailMode != DetailMode.DETAILED) { widget = ListTile( leading: icon, - title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + title: + AFormWidget.getSimpleLabelValue(label, formItem, presentationMode), ); } else { widget = ListTile( @@ -1030,8 +1062,8 @@ class AutoCompleteStringComboWidget extends AFormWidget { if (itemReadonly && presentationMode.detailMode != DetailMode.DETAILED) { widget = ListTile( leading: icon, - title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + title: + AFormWidget.getSimpleLabelValue(label, formItem, presentationMode), ); } else { widget = ListTile( @@ -1109,7 +1141,8 @@ class ConnectedStringComboWidget extends AFormWidget { widget = ListTile( leading: icon, title: AFormWidget.getSimpleLabelValue( - label, finalString, presentationMode), + label, formItem, presentationMode, + forceValue: finalString), ); } else { widget = ListTile( @@ -1246,8 +1279,8 @@ class MultiStringComboWidget extends AFormWidget { // ! TODO widget = ListTile( leading: icon, - title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + title: + AFormWidget.getSimpleLabelValue(label, formItem, presentationMode), ); } else { widget = ListTile( diff --git a/lib/com/hydrologis/flutterlibs/forms/forms_widgets.dart b/lib/com/hydrologis/flutterlibs/forms/forms_widgets.dart index 5cc3373..5bf2536 100644 --- a/lib/com/hydrologis/flutterlibs/forms/forms_widgets.dart +++ b/lib/com/hydrologis/flutterlibs/forms/forms_widgets.dart @@ -567,7 +567,7 @@ Tuple2? getWidget( ListTile( leading: icon, title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + label, formItem, presentationMode), ), false); } @@ -587,7 +587,7 @@ Tuple2? getWidget( ListTile( leading: icon, title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + label, formItem, presentationMode), ), false); } @@ -637,7 +637,7 @@ Tuple2? getWidget( ListTile( leading: icon, title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + label, formItem, presentationMode), ), false); } @@ -662,7 +662,8 @@ Tuple2? getWidget( ListTile( leading: icon, title: AFormWidget.getSimpleLabelValue( - label, finalString, presentationMode), + label, formItem, presentationMode, + forceValue: finalString), ), false); } @@ -702,7 +703,7 @@ Tuple2? getWidget( ListTile( leading: icon, title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + label, formItem, presentationMode), ), false); } @@ -723,7 +724,7 @@ Tuple2? getWidget( ListTile( leading: icon, title: AFormWidget.getSimpleLabelValue( - label, valueString, presentationMode), + label, formItem, presentationMode), ), false); } @@ -1141,9 +1142,10 @@ class ComboboxWidgetState extends State { if (widget._presentationMode.isReadOnly && widget._presentationMode.detailMode != DetailMode.DETAILED) { return AFormWidget.getSimpleLabelValue( - widget._label, - found != null ? found.label : (value == null ? "" : value.toString()), - widget._presentationMode); + widget._label, widget._formItem, widget._presentationMode, + forceValue: found != null + ? found.label + : (value == null ? "" : value.toString())); } return Column( @@ -2046,9 +2048,11 @@ class MultiComboWidgetState extends State { if (widget._isReadOnly && widget._presentationMode.detailMode != DetailMode.DETAILED) { return AFormWidget.getSimpleLabelValue( - widget._label, - selectedItems.map((e) => e.label).join(";"), - widget._presentationMode); + widget._label, + widget._formItem, + widget._presentationMode, + forceValue: selectedItems.map((e) => e.label).join(";"), + ); } return Center(