--- url: "https://grpc.io/docs/languages/dart/quickstart" titulek: "Quick start | Dart | gRPC" h1: "Quick start" popis: "This guide gets you started with gRPC in Dart with a simple working example." jazyk: "en" kanonicka: "https://grpc.io/docs/languages/dart/quickstart/" drobecky: ["Docs", "Languages", "Dart", "Quick start"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 21:02:06" znaku: 7001 slov: 773 kodovani: "utf-8" sha256: "358c1e413373b9036a4379ab42fdc6f7c26027e018eafda8e4acf7ea33c08a4d" --- # Quick start This guide gets you started with gRPC in Dart with a simple working example. Contents # Quick start This guide gets you started with gRPC in Dart with a simple working example. ### Prerequisites - **[Dart](https://dart.dev)** version 2.12 or higher, through the Dart or [Flutter](https://flutter.dev) SDKs For installation instructions, see [Install Dart](https://dart.dev/install) or [Install Flutter](https://flutter.dev/docs/get-started/install). - **[Protocol buffer](https://protobuf.dev) compiler**, `protoc`, [version 3](https://protobuf.dev/programming-guides/proto3) For installation instructions, see [Protocol Buffer Compiler Installation](/docs/protoc-installation/). - **Dart plugin** for the protocol compiler: 1. Install the protocol compiler plugin for Dart (`protoc-gen-dart`) using the following command: `dart pub global activate protoc_plugin` 2. Update your `PATH` so that the `protoc` compiler can find the plugin: `export PATH="$PATH:$HOME/.pub-cache/bin"` #### Note Dart gRPC supports the Flutter and Server platforms. ### Get the example code The example code is part of the [grpc-dart](https://github.com/grpc/grpc-dart) repo. 1. [Download the repo as a zip file](https://github.com/grpc/grpc-dart/archive/master.zip) and unzip it, or clone the repo: `git clone https://github.com/grpc/grpc-dart` 2. Change to the quick start example directory: `cd grpc-dart/example/helloworld` ### Run the example From the `example/helloworld` directory: 1. Download package dependencies: `dart pub get` 2. Run the server: `dart bin/server.dart` 3. From another terminal, run the client: `dart bin/client.dart Greeter client received: Hello, world!` Congratulations! You’ve just run a client-server application with gRPC. ### Update the app In this section you’ll update the app to make use of an extra server method. The gRPC service is defined using [protocol buffers](https://protobuf.dev). To learn more about how to define a service in a `.proto` file, see [Basics tutorial](../basics/). For now, all you need to know is that both the server and the client stub have a `SayHello()` RPC method that takes a `HelloRequest` parameter from the client and returns a `HelloReply` from the server, and that the method is defined like this: ``` // The greeting service definition. service Greeter { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) {} } // The request message containing the user's name. message HelloRequest { string name = 1; } // The response message containing the greetings message HelloReply { string message = 1; } ``` #### Update the gRPC service Open `protos/helloworld.proto` and add a new `SayHelloAgain()` method, with the same request and response types: ``` // The greeting service definition. service Greeter { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) {} // Sends another greeting rpc SayHelloAgain (HelloRequest) returns (HelloReply) {} } // The request message containing the user's name. message HelloRequest { string name = 1; } // The response message containing the greetings message HelloReply { string message = 1; } ``` Remember to save the file! #### Regenerate gRPC code Before you can use the new service method, you need to recompile the updated proto file. From the `example/helloworld` directory, run the following command: ``` protoc --dart_out=grpc:lib/src/generated -Iprotos protos/helloworld.proto ``` You’ll find the regenerated request and response classes, and client and server classes in the `lib/src/generated` directory. Now implement and call the new RPC in the server and client code, respectively. #### Update the server Open `bin/server.dart` and add the following `sayHelloAgain()` method to the `GreeterService` class: ``` class GreeterService extends GreeterServiceBase { @override Future sayHello(ServiceCall call, HelloRequest request) async { return HelloReply()..message = 'Hello, ${request.name}!'; } @override Future sayHelloAgain(ServiceCall call, HelloRequest request) async { return HelloReply()..message = 'Hello again, ${request.name}!'; } } ``` #### Update the client Add a call to `sayHelloAgain()` in `bin/client.dart` like this: ``` Future main(List args) async { final channel = ClientChannel( 'localhost', port: 50051, options: const ChannelOptions(credentials: ChannelCredentials.insecure()), ); final stub = GreeterClient(channel); final name = args.isNotEmpty ? args[0] : 'world'; try { var response = await stub.sayHello(HelloRequest()..name = name); print('Greeter client received: ${response.message}'); response = await stub.sayHelloAgain(HelloRequest()..name = name); print('Greeter client received: ${response.message}'); } catch (e) { print('Caught error: $e'); } await channel.shutdown(); } ``` ### Run the updated app Run the client and server like you did before. Execute the following commands from the `example/helloworld` directory: 1. Run the server: `dart bin/server.dart` 2. From another terminal, run the client. This time, add a name as a command-line argument: `dart bin/client.dart Alice` You’ll see the following output: `Greeter client received: Hello, Alice! Greeter client received: Hello again, Alice!` ### Contributing If you experience problems with Dart gRPC or have a feature request, [create an issue](https://github.com/grpc/grpc-dart/issues/new) over the [grpc-dart](https://github.com/grpc/grpc-dart) repo. ### What’s next - Learn how gRPC works in [Introduction to gRPC](/docs/what-is-grpc/introduction/) and [Core concepts](/docs/what-is-grpc/core-concepts/) . - Work through the [Basics tutorial](../basics/) . - Explore the [API reference](../api) . Last modified May 11, 2026: [Replace developers.google.com/protocol-buffers with protobuf.dev (#1502) (2e86d79)](https://github.com/grpc/grpc.io/commit/2e86d797df142cc555dced79016519515cc24f7a) [View page source](https://github.com/grpc/grpc.io/tree/main/content/en/docs/languages/dart/quickstart.md) [Edit this page](https://github.com/grpc/grpc.io/edit/main/content/en/docs/languages/dart/quickstart.md) [Create child page](https://github.com/grpc/grpc.io/new/main/content/en/docs/languages/dart/quickstart.md?filename=change-me.md&value=---%0Atitle%3A+%22Long+Page+Title%22%0AlinkTitle%3A+%22Short+Nav+Title%22%0Aweight%3A+100%0Adescription%3A+%3E-%0A+++++Page+description+for+heading+and+indexes.%0A---%0A%0A%23%23+Heading%0A%0AEdit+this+template+to+create+your+new+page.%0A%0A%2A+Give+it+a+good+name%2C+ending+in+%60.md%60+-+e.g.+%60getting-started.md%60%0A%2A+Edit+the+%22front+matter%22+section+at+the+top+of+the+page+%28weight+controls+how+its+ordered+amongst+other+pages+in+the+same+directory%3B+lowest+number+first%29.%0A%2A+Add+a+good+commit+message+at+the+bottom+of+the+page+%28%3C80+characters%3B+use+the+extended+description+field+for+more+detail%29.%0A%2A+Create+a+new+branch+so+you+can+preview+your+new+file+and+request+a+review+via+Pull+Request.%0A) [Create documentation issue](https://github.com/grpc/grpc.io/issues/new?title=Quick%20start) [Create project issue](https://github.com/grpc/grpc.io/issues/new)