Skip to content

Commit

Permalink
better view of encoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
moovida committed Dec 2, 2024
1 parent c346cd9 commit f6e1f5b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 24 deletions.
57 changes: 45 additions & 12 deletions lib/com/hydrologis/flutterlibs/forms/form_item_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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(
Expand All @@ -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),
),
],
Expand All @@ -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),
),
],
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
28 changes: 16 additions & 12 deletions lib/com/hydrologis/flutterlibs/forms/forms_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ Tuple2<ListTile, bool>? getWidget(
ListTile(
leading: icon,
title: AFormWidget.getSimpleLabelValue(
label, valueString, presentationMode),
label, formItem, presentationMode),
),
false);
}
Expand All @@ -587,7 +587,7 @@ Tuple2<ListTile, bool>? getWidget(
ListTile(
leading: icon,
title: AFormWidget.getSimpleLabelValue(
label, valueString, presentationMode),
label, formItem, presentationMode),
),
false);
}
Expand Down Expand Up @@ -637,7 +637,7 @@ Tuple2<ListTile, bool>? getWidget(
ListTile(
leading: icon,
title: AFormWidget.getSimpleLabelValue(
label, valueString, presentationMode),
label, formItem, presentationMode),
),
false);
}
Expand All @@ -662,7 +662,8 @@ Tuple2<ListTile, bool>? getWidget(
ListTile(
leading: icon,
title: AFormWidget.getSimpleLabelValue(
label, finalString, presentationMode),
label, formItem, presentationMode,
forceValue: finalString),
),
false);
}
Expand Down Expand Up @@ -702,7 +703,7 @@ Tuple2<ListTile, bool>? getWidget(
ListTile(
leading: icon,
title: AFormWidget.getSimpleLabelValue(
label, valueString, presentationMode),
label, formItem, presentationMode),
),
false);
}
Expand All @@ -723,7 +724,7 @@ Tuple2<ListTile, bool>? getWidget(
ListTile(
leading: icon,
title: AFormWidget.getSimpleLabelValue(
label, valueString, presentationMode),
label, formItem, presentationMode),
),
false);
}
Expand Down Expand Up @@ -1141,9 +1142,10 @@ class ComboboxWidgetState<T> extends State<ComboboxWidget> {
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(
Expand Down Expand Up @@ -2046,9 +2048,11 @@ class MultiComboWidgetState<T> extends State<MultiComboWidget> {
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(
Expand Down

0 comments on commit f6e1f5b

Please sign in to comment.