asBool method

List<bool> asBool({
  1. String? id,
})

Implementation

List<bool> asBool({String? id}) {
  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);
      if (item == null) return [false];
      return [item.active];
    } else {
      // We're going to merge this all together into one long string of values
      return values.map((item) => item.active).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);
      if (item == null) return [false];
      return item.value != "" ? [true] : [false];
    } else {
      // We're going to merge this all together into one long string of values
      return values.map((item) => item.value != "" ? true : false).toList();
    }
  }
  return [];
}