asyncGetterCodeForField function

String asyncGetterCodeForField (FieldElement field, { bool returns: true })

Implementation

String asyncGetterCodeForField(FieldElement field, {bool returns = true}) {
  String code;
  switch (field.type.displayName) {
    case 'bool':
      code = '_adapter.getBool("${field.name}")';
      break;
    case 'int':
      code = '_adapter.getInt("${field.name}")';
      break;
    case 'List<String>':
      code = '_adapter.getStringList("${field.name}")';
      break;
    case 'double':
      code = '_adapter.getDouble("${field.name}")';
      break;
    case 'String':
    default:
      code = '_adapter.getString("${field.name}")';
      break;
  }

  final annotation = defaultValueAnnotation(field);
  if (annotation != null) {
    code =
        '$code.then((value){ return value ?? ${getDefaultValue(field, annotation)};})';
  }

  return '${returns ? 'return ' : ''}$code${returns ? ';' : ''}';
}