generateAsyncSetter function

Method generateAsyncSetter (FieldElement field, { bool returns: true })

Implementation

Method generateAsyncSetter(FieldElement field, {bool returns = true}) {
  String code = '_cache["${field.name}"] = value; \n';
  switch (field.type.displayName) {
    case 'bool':
      code +=
          '${returns ? 'return ' : ''} _adapter.setBool("${field.name}", value);';
      break;
    case 'int':
      code +=
          '${returns ? 'return ' : ''} _adapter.setInt("${field.name}", value);';
      break;
    case 'String':
      code +=
          '${returns ? 'return ' : ''} _adapter.setString("${field.name}", value);';
      break;
    case 'List<String>':
      code +=
          '${returns ? 'return ' : ''} _adapter.setStringList("${field.name}", value);';
      break;
    case 'double':
      code +=
          '${returns ? 'return ' : ''} _adapter.setDouble("${field.name}", value);';
      break;
  }

  return Method((b) => b
    ..name = "${field.name}AsyncSet"
    ..body = Code(code)
    ..requiredParameters.add(Parameter((b) => b
      ..name = 'value'
      ..type = refer(field.type.displayName)))
    ..returns = refer("Future<void>"));
}