Added null check for primitives
This commit is contained in:
parent
7acb1f5f4c
commit
679c6fe8e3
1 changed files with 10 additions and 2 deletions
|
@ -198,11 +198,19 @@ String findFromJsonHandling(
|
|||
'int53': 'int',
|
||||
'Bool': 'bool',
|
||||
};
|
||||
final predefinedDefault = {
|
||||
'double': '0',
|
||||
'string': "''",
|
||||
'int32': '0',
|
||||
'int53': '0',
|
||||
'Bool': 'false',
|
||||
};
|
||||
|
||||
if (predefined.containsKey(type)) {
|
||||
return '$varAccess as ${predefined[type]}';
|
||||
return '($varAccess as ${predefined[type]}?) ?? ${predefinedDefault[type]}';
|
||||
}
|
||||
else if (type == 'int64') {
|
||||
return 'int.parse($varAccess)';
|
||||
return "int.parse($varAccess ?? '0')";
|
||||
}
|
||||
else if (type == 'bytes') {
|
||||
return 'base64.decode($varAccess)';
|
||||
|
|
Loading…
Add table
Reference in a new issue