getValue<T> method

T getValue<T>(
  1. String name, {
  2. T? defaultValue,
  3. bool allowEmpty = false,
})

Implementation

T getValue<T>(String name, {T? defaultValue, bool allowEmpty = false}) {
  final value = this[name] ?? defaultValue;
  if (value is! T) {
    throw ArgumentError.value(
        value, null, 'Invalid value provided for $name');
  }
  if (value != null && value.toString().trim().isEmpty && !allowEmpty) {
    throw ArgumentError.value(
        value, null, 'Empty value not allowed for $name');
  }
  return value;
}