Flutter dart GRPC client - null safety

We get these errors with GRPC client. Do you have a version for null safety ?

We have a null safe version of our servicestack Dart library for Dart Add ServiceStack Reference but we don’t maintain any of the gRPC proto client libraries, that comes directly from grpc.io Dart library maintainers.

1 Like

Does the ServiceStack 2.0 for dart work for flutter-web ? (for StreamServerEvents?)

The ServiceStack Dart library doesn’t have an SSE/Server Events client.

what package we should use for StreamServerEvents.
I can’t understand this command

rpc ServerStreamServerEvents(StreamServerEvents) returns (stream StreamServerEventsResponse) {}

do we create the protoc client ? not only the protobuf for request -response

Dart’s normal grpc packages, I wouldn’t expect there’d be others maintained for Dart.

For mobile Flutter application, connection with Servicestack API is working. The same with GRPC service.
But in flutter web we can’t use that objects and with the web ones we have errors
For ServicestackAPI Connection we use that:

var client = new JsonWebClient(“https://www.techstacks.io”);
void _getContext() async{
var response = await client.get(GetTechnology(slug:“flutter”));
_counter = response.technology.hashCode;
}

and we get errors like this:

TypeError: Cannot read property ‘statusCode’ of null
at http://localhost:61038/packages/servicestack/web_client.dart.lib.js:702:31
at web_client.JsonWebClient.new.handleError >

This error seems to come from inside of web_client.dart library
For GrpcWeb we use the GrpcWebClientChannel

Future doRemoteCall() async {
final channel = GrpcWebClientChannel.xhr(Uri.parse(‘todoworld.servicestack.net:50054’));
final client = EchoServiceClient(channel);
return (await client.echo(EchoRequest()…message = ‘hello’)).message;
}

And we are getting this error back:

Error: gRPC Error (code: 14, codeName: UNAVAILABLE, message: XhrConnection status 0, details: null, rawResponse: )
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 909:28 get current
packages/grpc/src/client/transport/xhr_transport.dart 122:22

compiled with unsound null safety

This is the flutter mobile code working normally
For mobile Flutter application,
Connection with Servicestack API is working with code below

var client1 = JsonServiceClient(“https://techstacks.io”);
void _callService() async {
var response = await client1.get(GetTechnology(slug:“flutter”));
setState(() {
result = response.technology!.description!;
});
}

Connection with grpc service also working

GrpcServicesClient client1 = GrpcServicesClient(
ClientChannel(‘todoworld.servicestack.net’, port:50054,
options:ChannelOptions(credentials: ChannelCredentials.insecure())));
void _callGrpcService() async {
var response = await client1.getHello(Hello()…name=“Flutter gRPC”);
setState(() {
result = response.result;
});
}

I’m assuming you’re running into a CORS error, you wont be able to make cross domain requests from any website unless the cross domain server explicitly authorizes the origin url you’re making the request from.

What’s the actual HTTP Request/Response headers made by the web client?

We can answer you tomorrow when the developer works again. I think he used your code example from the documentation. He calls the “https://www.techstacks.io”

You can’t break web laws, don’t try to make cross origin requests unless you know it’s explicitly allowed from your domain, make it to your own APIs that you can control instead, if the API is hosted on a different domain from the Web App register the CorsFeature plugin with the origin you’re calling from.

I know for the CORS feature in our API. Developer tried to test if the GRPC works as the example for the flutter -web

@mythz we have another problem now. The request was served by the service but it returns this error
image (24)

Can you help please?

It’s as it says, gRPC Web isn’t supported.

what do you mean?
we can’t use the gRPC from flutter - web? streamserverEvents ?

gRPC Web isn’t natively supported as web clients are not able to communicate directly with gRPC endpoints, it required an Envoy Proxy to forward the gRPC Web Requests to native gRPC endpoints.

We had read it. But you wrote

we instead recommended using ServiceStack HTTP JSON Services, made possible since ServiceStack’s gRPC Service implementations are also made available over REST-ful HTTP APIs

How we should do it? an example?

That just says to use normal HTTP/Service Clients to call the ServiceStack APIs over HTTP/JSON as-is standard for API Requests from browsers.

We want streamserverEvents with gRPC How to suceed it ? only with anEnvoy Proxy ? an example of that? or we should search the internet?

For Websites you would need to go through a gRPC Web Proxy like Envoy Proxy, though I’ve never tried using it myself, essentially all Websites are going to call HTTP APIs instead.