toArray function Null safety

List toArray(
  1. {required String type,
  2. required String stringValue}
)

Converts a Postgres Array into a native JS array

@example toArray('{1,2,3,4}', 'int4')
//=> [1,2,3,4]
@example toArray('{}', 'int4')
//=> []

Implementation

List<dynamic> toArray({required String type, required String stringValue}) {
  // this takes off the '{' & '}'
  final stringEnriched = stringValue.substring(1, stringValue.length - 1);

  // converts the string into an array
  // if string is empty (meaning the array was empty), an empty array will be immediately returned
  final stringArray =
      stringEnriched.isNotEmpty ? stringEnriched.split(',') : <String>[];
  final array = stringArray.map((string) => convertCell(type, string)).toList();
  return array;
}