asString method

String asString({
  1. String? id,
  2. String delimiter = ", ",
  3. String fallback = "",
})

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;
}