getList<T> method

List<T> getList<T>()

Reads the ConstantReader instance and returns an instance of List<T>.

Throws ErrorOf if an instance of List<T> can not be constructed.

Implementation

List<T> getList<T>() {
  if (!holdsA<List<T>>()) {
    throw ErrorOf<ConstantReader>(
        message: 'Input does not represent an object of type <List<$T>',
        invalidState: 'Input represents an object of type '
            '$dartType.');
  }
  if (!_decoders.containsKey(T) && T != dynamic) {
    throw ErrorOf<ConstantReader>(
        message: 'Could not read list-entry value of type [$T].',
        invalidState: 'A decoder function for type [$T] is missing.',
        expectedState: 'Use addDecoder<$T>() to register a decoder '
            'function for type [$T].');
  }
  return listValue.map((item) => ConstantReader(item).get<T>()).toList();
}