Skip to content

Commit f6e1f5b

Browse files
committed
better view of encoded values
1 parent c346cd9 commit f6e1f5b

File tree

2 files changed

+61
-24
lines changed

2 files changed

+61
-24
lines changed

lib/com/hydrologis/flutterlibs/forms/form_item_widgets.dart

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,39 @@ abstract class AFormWidget {
7878
}
7979

8080
static Widget getSimpleLabelValue(
81-
String label, String value, PresentationMode pm) {
81+
String label, SmashFormItem item, PresentationMode pm,
82+
{String? forceValue}) {
83+
dynamic value = forceValue;
84+
if (value == null) {
85+
value = item.value;
86+
if (value == null) {
87+
return Container();
88+
} else if (value is List && value.isEmpty) {
89+
return Container();
90+
}
91+
// if value has a label in the map, use it
92+
List<String> valueLabels = [];
93+
if (item.map["values"] != null &&
94+
item.map["values"]?["items"] != null &&
95+
item.map["values"]?["items"] is List) {
96+
for (var listItem in item.map["values"]?["items"]) {
97+
var itemMap = listItem["item"];
98+
var itemLabel = itemMap?["label"];
99+
var itemValue = itemMap?["value"];
100+
if (itemLabel == null || itemValue == null) {
101+
continue;
102+
}
103+
if (itemValue == value ||
104+
(value is List && value.contains(itemValue))) {
105+
valueLabels.add(itemLabel);
106+
}
107+
}
108+
}
109+
if (valueLabels.isNotEmpty) {
110+
value = valueLabels.join(", ");
111+
}
112+
}
113+
82114
Widget field;
83115
if (pm.detailMode == DetailMode.NORMAL) {
84116
field = Column(
@@ -89,7 +121,7 @@ abstract class AFormWidget {
89121
color: pm.labelTextColor, bold: pm.doLabelBold),
90122
Padding(
91123
padding: const EdgeInsets.only(left: 12.0, top: 8),
92-
child: SmashUI.normalText(value,
124+
child: SmashUI.normalText(value.toString(),
93125
color: pm.valueTextColor, bold: pm.doValueBold),
94126
),
95127
],
@@ -103,7 +135,7 @@ abstract class AFormWidget {
103135
color: pm.labelTextColor, bold: pm.doLabelBold),
104136
Padding(
105137
padding: const EdgeInsets.only(left: 12.0),
106-
child: SmashUI.normalText(value,
138+
child: SmashUI.normalText(value.toString(),
107139
color: pm.valueTextColor, bold: pm.doValueBold),
108140
),
109141
],
@@ -718,8 +750,8 @@ class DateWidget extends AFormWidget {
718750
if (itemReadonly && presentationMode.detailMode != DetailMode.DETAILED) {
719751
widget = ListTile(
720752
leading: icon,
721-
title: AFormWidget.getSimpleLabelValue(
722-
label, valueString, presentationMode),
753+
title:
754+
AFormWidget.getSimpleLabelValue(label, formItem, presentationMode),
723755
);
724756
} else {
725757
widget = ListTile(
@@ -786,8 +818,8 @@ class TimeWidget extends AFormWidget {
786818
if (itemReadonly && presentationMode.detailMode != DetailMode.DETAILED) {
787819
widget = ListTile(
788820
leading: icon,
789-
title: AFormWidget.getSimpleLabelValue(
790-
label, valueString, presentationMode),
821+
title:
822+
AFormWidget.getSimpleLabelValue(label, formItem, presentationMode),
791823
);
792824
} else {
793825
widget = ListTile(
@@ -1030,8 +1062,8 @@ class AutoCompleteStringComboWidget extends AFormWidget {
10301062
if (itemReadonly && presentationMode.detailMode != DetailMode.DETAILED) {
10311063
widget = ListTile(
10321064
leading: icon,
1033-
title: AFormWidget.getSimpleLabelValue(
1034-
label, valueString, presentationMode),
1065+
title:
1066+
AFormWidget.getSimpleLabelValue(label, formItem, presentationMode),
10351067
);
10361068
} else {
10371069
widget = ListTile(
@@ -1109,7 +1141,8 @@ class ConnectedStringComboWidget extends AFormWidget {
11091141
widget = ListTile(
11101142
leading: icon,
11111143
title: AFormWidget.getSimpleLabelValue(
1112-
label, finalString, presentationMode),
1144+
label, formItem, presentationMode,
1145+
forceValue: finalString),
11131146
);
11141147
} else {
11151148
widget = ListTile(
@@ -1246,8 +1279,8 @@ class MultiStringComboWidget extends AFormWidget {
12461279
// ! TODO
12471280
widget = ListTile(
12481281
leading: icon,
1249-
title: AFormWidget.getSimpleLabelValue(
1250-
label, valueString, presentationMode),
1282+
title:
1283+
AFormWidget.getSimpleLabelValue(label, formItem, presentationMode),
12511284
);
12521285
} else {
12531286
widget = ListTile(

lib/com/hydrologis/flutterlibs/forms/forms_widgets.dart

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ Tuple2<ListTile, bool>? getWidget(
567567
ListTile(
568568
leading: icon,
569569
title: AFormWidget.getSimpleLabelValue(
570-
label, valueString, presentationMode),
570+
label, formItem, presentationMode),
571571
),
572572
false);
573573
}
@@ -587,7 +587,7 @@ Tuple2<ListTile, bool>? getWidget(
587587
ListTile(
588588
leading: icon,
589589
title: AFormWidget.getSimpleLabelValue(
590-
label, valueString, presentationMode),
590+
label, formItem, presentationMode),
591591
),
592592
false);
593593
}
@@ -637,7 +637,7 @@ Tuple2<ListTile, bool>? getWidget(
637637
ListTile(
638638
leading: icon,
639639
title: AFormWidget.getSimpleLabelValue(
640-
label, valueString, presentationMode),
640+
label, formItem, presentationMode),
641641
),
642642
false);
643643
}
@@ -662,7 +662,8 @@ Tuple2<ListTile, bool>? getWidget(
662662
ListTile(
663663
leading: icon,
664664
title: AFormWidget.getSimpleLabelValue(
665-
label, finalString, presentationMode),
665+
label, formItem, presentationMode,
666+
forceValue: finalString),
666667
),
667668
false);
668669
}
@@ -702,7 +703,7 @@ Tuple2<ListTile, bool>? getWidget(
702703
ListTile(
703704
leading: icon,
704705
title: AFormWidget.getSimpleLabelValue(
705-
label, valueString, presentationMode),
706+
label, formItem, presentationMode),
706707
),
707708
false);
708709
}
@@ -723,7 +724,7 @@ Tuple2<ListTile, bool>? getWidget(
723724
ListTile(
724725
leading: icon,
725726
title: AFormWidget.getSimpleLabelValue(
726-
label, valueString, presentationMode),
727+
label, formItem, presentationMode),
727728
),
728729
false);
729730
}
@@ -1141,9 +1142,10 @@ class ComboboxWidgetState<T> extends State<ComboboxWidget> {
11411142
if (widget._presentationMode.isReadOnly &&
11421143
widget._presentationMode.detailMode != DetailMode.DETAILED) {
11431144
return AFormWidget.getSimpleLabelValue(
1144-
widget._label,
1145-
found != null ? found.label : (value == null ? "" : value.toString()),
1146-
widget._presentationMode);
1145+
widget._label, widget._formItem, widget._presentationMode,
1146+
forceValue: found != null
1147+
? found.label
1148+
: (value == null ? "" : value.toString()));
11471149
}
11481150

11491151
return Column(
@@ -2046,9 +2048,11 @@ class MultiComboWidgetState<T> extends State<MultiComboWidget> {
20462048
if (widget._isReadOnly &&
20472049
widget._presentationMode.detailMode != DetailMode.DETAILED) {
20482050
return AFormWidget.getSimpleLabelValue(
2049-
widget._label,
2050-
selectedItems.map((e) => e.label).join(";"),
2051-
widget._presentationMode);
2051+
widget._label,
2052+
widget._formItem,
2053+
widget._presentationMode,
2054+
forceValue: selectedItems.map((e) => e.label).join(";"),
2055+
);
20522056
}
20532057

20542058
return Center(

0 commit comments

Comments
 (0)