fetch<T> method
Get a config value under the given path
.
Throws ConfigPathException if value does not exist.
If a null return value is preferred instead, simply set a nullable
type for T
and no exception will be thrown.
Valid types for T
(nullable, as well as non-nullable)
are String, int, double, bool, DateTime, Uint8List,
List<int> or List<String> or Map<String, dynamic>.
If the value does not match the requested type or cannot be parsed into the given type, a ConfigTypeException is thrown.
Implementation
T fetch<T>(ConfigPath path) {
try {
final raw = path.getFrom(_configMap);
try {
return decodeTyped<T>(raw);
} on CodecException catch (_) {
throw ConfigTypeException(path.toString(), T, raw.runtimeType);
}
} on ConfigPathException catch (_) {
if (null is T) {
return null as T;
} else {
rethrow;
}
}
}