build_grpc_channel 0.5.0 copy "build_grpc_channel: ^0.5.0" to clipboard
build_grpc_channel: ^0.5.0 copied to clipboard

The util builds gRPC channel for flutter web or other platforms conditionally, depending on the runtime environment

The package for building grpc channel depending on is it web or not

Features #

  • The util builds gRPC channel for flutter web or other platforms conditionally, depending on the runtime environment

Usage #

const webAppPort = 8888;
const someGrpcServicePort = 5555;
const host = 'http://127.0.0.1';

// for web I suggest to use Envoy as a proxy routing from webAppPort to someGrpcServicePort
int get port => kIsWeb ? webAppPort : someGrpcServicePort;

class SomeGrpcService {
  late final SomeGrpcClient stub;

  SomeGrpcService() {
    init();
  }

  void init() {
    final channel = buildGrpcChannel(host: host, port: port, secure: false);
    stub = SomeGrpcClient(channel);
  }

  Future<SomeRpcResponse> someRpc(SomeRpcRequest request) {
    final response = stub.sendQuestion(request);
    return response;
  }
}
7
likes
120
pub points
67%
popularity

Publisher

unverified uploader

The util builds gRPC channel for flutter web or other platforms conditionally, depending on the runtime environment

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

grpc

More

Packages that depend on build_grpc_channel