readPickleables<T> method

List<T> readPickleables<T>(
  1. String key,
  2. T depickler(
    1. Pickle pickle
    ), {
  3. List<T>? defaultValue,
})

Reads a List of Pickleables from this Pickle.

This will throw ArgumentError if the key is empty and no default value has been provided or PickleTypeError if the associated value is of a different type than expected.

Implementation

List<T> readPickleables<T>(
  final String key,
  final T Function(Pickle pickle) depickler, {
  final List<T>? defaultValue,
}) {
  try {
    return _readList(key)
        .map<T>((final Map<String, dynamic> map) => depickler(Pickle._(map)))
        .toList();
  } catch (error) {
    if (defaultValue != null) {
      return defaultValue;
    }
    rethrow;
  }
}