# Tutorial - Using Protobuf in Flutter

Recently, I have working on Futter project. However, I have found it quite difficult to install the Dart protobuf plugin on Linux. Here is my tutorial for you to save your time.

1. Install Dart

Following the instruction here to install Dart

Dart SDK

For me, I just download the deb file and install it.

After that we can use dart in terminal, but we cannot find pub . The reason is beacuse it is located in usr/lib/dart/bin Therefore, we’d better change the PATH permanently.

1. Change the PATH permanently for pub

Then add the following to the end of .profile

Logout and login again to let the modification take effect. Type pub in terminal, we will see it works.

1. Install protoc

The simplest way is to use to precompiled protoc binary and put it into PATH

Protobuf Release

For me, I download the protoc-3.6.1-osx-x86_64.zip. Unzip it, and put protoc binary to /usr/bin

Then, we type protoc in terminal, we will see it works.

1. Install Dart protoc_plugin

In the terminal, type

Right now, I’m in China. For reasons known to all, I have to use the mirror

export PUB_HOSTED_URL=https://pub.flutter-io.cn

However, it is installed in \$HOME/.pub-cache/bin. We’d better make it into PATH again.

Using the same way in ~/.profile

Now, the last line looks like

You need to logout and login to again to take effect.

1. Compile from .proto file

Finally, we can compile .proto file to .dart file.

For me, I just go to the directory containing the .proto file, using the command below, and it will generate the .dart file(s) you need. You can copy them to your flutter project

2. Install protobuf runtime library

Don’t forget to install the runtime library by adding protobuf: ^0.11.0 in your dependency part of pubspec.yaml

That’s it! Hope it will save your time to build your flutter project with awesome protobuf!