Working with gRPC + Flutter on Windows
Lately I’ve been studying a bit of gRPC to check out how it works for mobile development using Flutter and I stumbled on an unexpected issue (which maybe isn’t that -really- unexpected): it’s not so trivial to install and configure all libraries you need to make gRPC work on your Windows machine.
So, here are all steps I did in order to make things work in a Windows development environment.
Step 1:
Based on the Dart quickstart we must first install the protocol compiler for Dart
dart pub global activate protoc_plugin
Step 2:
Now we must download the specific release of protobuf for Windows. In my case the latest version was protoc-3.17.3. Remeber to download the asset for win32 or win64.
Step 3
Once the download from Step 2 is done we can extract anywhere we’re comfortable and our system user has permission to read. In my case: C:\SDKs\protoc-3.17.3-win64
Step 4
Now we must add our extract file to our PATH in our system’s environment variables, including the subfolder “bin”. The complete path to add in my case is: “C:\SDKs\protoc-3.17.3-win64\bin”
Step 5
After installing the protoc_plugin (step 1), it’ll add in our user’s folders a “protoc-gen-dart.bat” which we must copy and paste in the same bin folder we added to our path in the previous step. In my case the “protoc-gen-dart.bat” file is located in:
C:\Users\<YOUR_USER>\AppData\Local\Pub\Cache\bin
The final result must look like this:
Result
After following all steps you now must be able to execute the command to generate all required compiled files from a proto such as:
protoc --dart_out=grpc:lib/src/generated -Iprotos protos/person.proto
And now you’re good to go and use gRPC with Dart on a Windows machine!