getDefaultExpr method

String getDefaultExpr()

Returns a Dart expression that evaluates to this field's default value.

Returns "null" if unavailable, in which case FieldSet._getDefault() should be called instead.

Implementation

String getDefaultExpr() {
  if (isRepeated) return 'null';
  switch (descriptor.type) {
    case FieldDescriptorProto_Type.TYPE_BOOL:
      return _getDefaultAsBoolExpr('false')!;
    case FieldDescriptorProto_Type.TYPE_INT32:
    case FieldDescriptorProto_Type.TYPE_UINT32:
    case FieldDescriptorProto_Type.TYPE_SINT32:
    case FieldDescriptorProto_Type.TYPE_FIXED32:
    case FieldDescriptorProto_Type.TYPE_SFIXED32:
      return _getDefaultAsInt32Expr('0')!;
    case FieldDescriptorProto_Type.TYPE_STRING:
      return _getDefaultAsStringExpr("''")!;
    default:
      return 'null';
  }
}