Browse Source

Added null check for primitives

master
Kenneth Bruen 3 years ago
parent
commit
679c6fe8e3
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 12
      bin/tdlib_gen.dart

12
bin/tdlib_gen.dart

@ -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…
Cancel
Save