freewheelnat / flutter_plugins_help

Connecting Android and iOS developers to develop flutter plugins.
29 stars 1 forks source link

Golang plug-in #1

Open ghost opened 6 years ago

ghost commented 6 years ago

It's easy to compile golang for mobile. And then you have to write the wrappers for Android and iOS.

My idea is to use protobuf. You can codegen from the protobuf the golang side and then the same to pass through the wrappers on then codegen the dart code.

The Bluetooth plugin for flutter uses protobufs to do this. It's the only one using this technique.

I think that writing a codegenerator for the above scenarios will make it much easier for everyone to write plugins because protobuf is language agnostic.

Writing this codegenerator in golang also makes it very easy for everyone to use it no matter what desktop they are on too because there is no external libs needed.

What do you think. ?

Getting a hello world going you be a great first step.

I use grpc and protobuf to codegen all gopherjs and wasm code now. I can add some links if need be.

I would be happy to collaborate with anyone on this.

Also the Flutter team are going to make Platform Services available soon so you can write services this way soon too and not just plugins I think.

freewheelnat commented 6 years ago

I'm a little unclear re your idea, namely is it about being able to use golang or is it about being able to use protobufs for writing plugins?

I'm all for using protobufs, but why not use Protobuf Dart, Java or Kotlin, and Swift tools directly (to generate iOS, Android, and Dart code)? Or do you feel those tools are too cumbersome to use (one for each language) and your idea is about writing a code generator that works for all the languages required in a Flutter plugin?

ghost commented 6 years ago

Its both.. You use Protobuf Dart, Java or Kotlin, and Swift, but you also want to use golang and i will explain why.

  1. lets say you have a ton of golang code. Maybe your writing a enterprise app and you want to share logic on the flutter side. You have a db also that you want to also exist on the flutter side.

  2. So you use protobufs to expose your library

  3. then you code gen the bindings. this code gens the layers above which is java and swift ( USING ITS INTERNAL PROTOBUF aspects ) and then its all exposed to Flutter. You can also code gen the flutter Method Channels too because its protobuf and you have all the data on the methods already from the protobuf IDL.

Also this is related https://github.com/uber/prototool

Its because i write all my code in golang for server side stuff and i want to share code with flutter. most large golang projects use protobug and grpc. cockroachdb, dgraph. You can even expose boltdb over grpc.

a simpel example: https://github.com/asdine/storm#import-storm This will run on mobiles for sure because its pure golang. You can easily expose this over protobuf.


Also here is a good basic example: https://github.com/go-jakarta/slides/tree/master/02-gomobile-and-grpc/src

ghost commented 6 years ago

A Better example

https://github.com/bkono/msgme

Ironically built for Fuse which is a competitor for Flutter :) But golang and protobuf work for both

freewheelnat commented 6 years ago

Thanks for clarifying, I understand now.

ghost commented 6 years ago

This technique will also work for Flutter Desktop also because its just golang.

Currently on Flutter Desktop they are insisting that the embedder wrap is built in cpp. The Plugin story is not fleshed out by the Google Team.

But its ok, because you can connect the cpp to golang and so any plugin like functionality you want can be done there in golang. Or even easier which is what i currently do, you run run the golang code as a service on the Desktop and the Flutter code calls it over GRPC. You can also use Protobuf without GRPC and add your own transport but i have not tried this.

Using golang a Protobuf & GRPC in tandem with Flutter makes this much easier.

Your cloud and server code written in golang can interact directly with your goalng code on mobiles and desktops.