asString method
Implementation
String asString({String? id, String delimiter = ", ", String fallback = ""}) {
String output = "";
if (type == FieldType.bool) {
if (id != null) {
// Return a single subvalue. We're checking if it exists.
final item = values.firstWhereOrNull((data) => data.id == id);
output = item?.active ?? false ? item?.value ?? "" : "";
} else {
// We're going to merge this all together into one long string of values
output = values.map((item) => item.value).join(delimiter);
}
} else if (type == FieldType.string) {
if (id != null) {
// Return a single subvalue. We're checking if it exists.
final item = values.firstWhereOrNull((data) => data.id == id);
output = item?.value ?? "";
} else {
// We're going to merge this all together into one long string of values
output = values.map((item) => item.value).join(delimiter);
}
}
return output != "" ? output : fallback;
}