Skip to content

optional in protobuf not working in grpc-dart #599

Closed
@yingshaoxo

Description

@yingshaoxo

What I wrote

Here is my protobuf code:

syntax = "proto3";
package account_storage_service;

option go_package = "./account_storage_service";

service AccountStorageService {
    rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
}

message CreateUserRequest {
    optional string email = 1;
}

message CreateUserResponse {
    string result = 1;
    optional string error = 2;
}

Here is my grpc build command:

protoc --dart_out=grpc:lib/generated_grpc --proto_path ../party_protocols/protocols --experimental_allow_proto3_optional account_storage_service.proto

Here is my flutter code:

CreateUserRequest createUserRequest = CreateUserRequest();
createUserRequest.email = updateUserRequest.email;

CreateUserResponse response = await client.createUser(createUserRequest,
          options: get_JWT_CallOptions_for_GRPC());
if (response.error != null && response.error != "") {
    return default_response;
}

image

What I expect

Theemail property in CreateUserRequest should be a null-safe variable, which means it could be null

The error property in CreateUserResponse should be a null-safe variable, which means it could be null

What I see is

They are all not null-able variables, it seems like the compiler ignores the optional string in the protobuf definition.

image

image

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions