Flutter ❤ GRPC

Using flutter with a GRPC backend and living the HTTP/2 life!

Preface

A few months ago, I decided to write an app for finding people around you with similar interests with the help of events. Having experience only in Android development, I couldn’t attempt to do purely native development for both Android and iOS, so I decided to go with something that targets both and requires the least amount of platform specific code. Choices:

React Native (Sort of an industry standard right now) Flutter (In beta at the time, now RC2)

I had used react-native for a couple of projects before, and I really loved RN for that, but there were so many issues with RN, and the whole trying to use native components by wrapping them and calling them over a JS bridge. That does bring a lot of inconsistencies with the native platform and react native’s wrapper. So, I decided to pick up Flutter.

With flutter, things were a bit different:

First I needed to learn dart, which seemingly isn’t all that bad, and quite easy to pick up. It has a syntax most people are familiar with (ES derived maybe?) and has a bunch on syntactic sugar on top of it, like arrow functions, argument only constructors that don’t require manual wiring etc. The structure of flutter apps is something that takes time getting used to, and believe me, I am still not used to it. With android you see things organised into views, controller and models, but with flutter everything is a widget, quite literally, which makes things complex quite easily if you don’t force yourself to cut components out to their separate widgets and create services etc. So it takes a bit of time getting used to. And then there is plugins, flutter mostly acts like a view framework of sorts and does lack a lot of basic functionality right now, like geolocation, local-notifications, handling of deep links and everything is handled by either third party plugins or some firebase plugins for now. Even maps lacks a first party plugin, its coming soon, follow this issue if you’re looking for that https://github.com/flutter/flutter/issues/19030

But with flutter, more precisely dart, there was complete support for GRPC, which JS lacked at that time, now there is grpc-web by the same team that built GRPC.

Anyway, let’s get to the main point of discussion, using GRPC with Flutter. When I decided I want to build a flutter app, I was also playing around with GRPC as a backend choice in GoLang. But the internet lacked any such documentation or blogposts of people attempting it. So I though I should do a small tutorial on making a simple app with a GRPC backend. I think I will be covering some more advanced topics like token (JWT) based auth, streams, TLS based authentication from apps etc in upcoming posts, but in this one, let’s build a simple hello world style app that talks to a GRPC server.