asStringList method
Implementation
List<String> asStringList({String? id, List<String> fallback = const []}) {
List<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.add(item?.active ?? false ? item?.id ?? "" : "");
} else {
// We're going to merge this all together into one long string of values
output.addAll(values.map((item) => item.id).toList());
}
} 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.add(item?.value ?? "");
} else {
// We're going to merge this all together into one long string of values
output.addAll(values.map((item) => item.value ?? "").toList());
}
}
return output != [] ? output : fallback;
}