arrayNodeOrNull<T> method

JsonArray<List<T>>? arrayNodeOrNull<T>(
  1. String key, {
  2. Function? decoder,
  3. List? childType,
})

Get JsonArray or null by String key.

Throws SquintException if key is not found.

Implementation

JsonArray<List<T>>? arrayNodeOrNull<T>(
  String key, {
  Function? decoder,
  List? childType,
}) {
  final element = byKey(key);

  if (element.data == null) {
    return null;
  }

  var array = byKey(key).data as List;
  if (decoder != null) {
    array = array.map((value) => decoder(value)).toList();
  }

  return JsonArray<List<T>>(
    key: key,
    data: array.cast<T>().toList(),
  );
}