getProviderCallCode method
String?
getProviderCallCode(
- DartType type, {
- String contextGetter = 'context',
- String keyGetter = 'key',
})
Implementation
String? getProviderCallCode(DartType type,
{String contextGetter = 'context', String keyGetter = 'key'}) {
final provider = 'valueProvider!.';
String? method;
if (type.isDartCoreInt) {
method = 'getInt($contextGetter, $keyGetter)';
} else if (type.isDartCoreDouble) {
method = 'getDouble($contextGetter, $keyGetter)';
} else if (type.isDartCoreString) {
method = 'getString($contextGetter, $keyGetter)';
} else if (type.isDartCoreBool) {
method = 'getBool($contextGetter, $keyGetter)';
}
if (isEnum(type)) {
method =
'getEnumValue(${type.getDisplayString(withNullability: false)}.values, $contextGetter, $keyGetter)';
}
if (method != null) {
return '''
try {
return ${provider + method};
} catch (exception) {
throw MissingValueProviderException();
}
''';
}
}