Skip to content

kjcodeacct/golang_flutter_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang & Flutter

Logo


Prerequisites

  • âś… Know golang
  • âś… Have introductory knowledge of MVVM, MVC, MVP, etc (UI development)

What is this exactly?

This is a great way to develop truly cross platform desktop and mobile applications rapidly, and beautifly.

It's an intersection between:

  • Flutter's approach to declarative UI.
  • Golang's great performant and system level language.

Powered by the go-flutter project


Who is this for?

This is for anyone who wants to build an application with a modern UI.

This could range from any of the following situations:

  • You have a mobile app you want to release on desktop.
  • Want to release a golang based app without electron or html.
  • You know golang, and want to get into mobile development or vice-versa.

Why?

Flutter

  • Flutter is a great UI oriented language, for rapidly getting to production across all platforms.

  • Has a great UI standard that renders natively on everythin from linux to IOS.

  • Desktop support for dart/flutter is spotty, and unofficially in beta.

Golang

  • Golang is a great system oriented language, for getting robust and fast (enough) code onto all platforms.

  • Has no real official UI tooling or even officially recommened UI.

  • Has primarily been developed with cli and server based applications in mind.


Quick Comparison

What else is available

Please note this is a list of packages I've used personally.

For a more exaustive list please go to https://github.com/avelino/awesome-go#gui


Pros & Cons

AKA is this too hipster for production?


Pros & Cons

Pros

  • Great workflow, can build and package a release for any platform (desktop, mobile, embedded) in moments.

  • Flutters UI is declaritive and a part of the business logic. No need to fuss with widget declarations, complex callbacks, async threads, etc.

  • Can target any desktop specific features with golang, and provide any mobile specific features with flutter/golang-mobile.

    • Can also have 2 seperate UI's for mobile and desktop experiences.
  • Flutter has been proven to be a stable platform for many of the large companies seen at https://flutter.dev/showcase


Pros & Cons

Cons

  • go-flutter is unofficial.

  • Flutter is less popular than kotlin, swift, and react-native, leading to a smaller community (currently)

  • Flutter is a new technology. Sometimes that's scary, and a hard sell.

  • Google occasionally likes to kill nice things

    • Should be noted Google dog-foods flutter for everything from Google Ads to Stadia.

How it works

High Level


How it works

In depth

---

Go Mobile

Will this bring all of the cool features go offers to mobile?

Yes, mostly.

Limitations:

  • Go mobile lacks some features
    • not all packages are compatible, and assume a desktop environment

How it works

Further Reading


Is this too hipster for production?

TLDR; No


Getting Started


Go-Flutter Tooling

Flutter

Flutter provides a CLI tool to build and package mobile & web applications.

List of commonly used commands:

# create your flutter app
$ flutter create golang_flutter_demo
# run your flutter app (android/ios)
$ flutter run
# build your bundled flutter app (android/ios)
# stores builds in golang_flutter_demo/build/app/outputs
$ flutter build apk
$ flutter build ios

Go-Flutter Tooling

Hover

Hover is the CLI tool that implements basic running, building and packaging a go-flutter application.

The options below match those provided by flutter:

# add desktop support to your flutter app
$ hover init
# run your golang flutter app (in native env)
$ hover run
# build your bundled go-flutter app
# stores builds in golang_flutter_demo/go/build/outputs
$ hover build linux
$ hover build macos
$ hover build windows

Go-Flutter "Plugins"

What is a "plugin" ?

  • It sounds fancy, but it's just an interface between go & dart.

An example plugin

https://github.com/go-flutter-desktop/examples/tree/master/plugin_tutorial/go-plugin-example/complex


Demo

  • Go to golang_flutter_demo directory
  • Run and build the app
    • hover run

Demo


Finally Some Code!

Lets see what it takes to run this.


Creating the Binding

Plugin

Create a go package with plugin bindings

gophershop/image_editor/main.go

func (this *Editor) InitPlugin(messenger plugin.BinaryMessenger) error {

	channel := plugin.NewMethodChannel(messenger, channelName, plugin.StandardMethodCodec{})
	channel.HandleFunc("editImage", this.parseEdit)
	return nil
}

Creating the Binding

Register the Plugin

Add package

go/cmd/options.go

flutter.AddPlugin(&image_editor.Editor{}),

Using the Binding

Call the plugin binding you made from your flutter code

lib/main.dart

static const image_editor_lib = const MethodChannel('gophershop/image_editor');
...
...
loadedImagePath = await image_editor_lib.invokeMethod("editImage", jsonText);

Quick Tips on Writing Plugins

  • use a common formats for communication i.e not raw structs
    • json, protobuffs, etc
  • write go code the same way as you would normally, error handling etc.
    • the plugin is not special, write it with your standard good practices for golang
  • if you are concerned about the layout mobile v desktop
    • mobile - main.dart
    • desktop - main_desktop.dart

Whats Next ?

  1. Checkout the golang_flutter_demo repo
  2. Add a different image editing feature from the provided image package
  3. Test the go-flutter build system and see if it's right for you.
  4. ???
  5. Become a hermit for the weekend and make a really cool app with go-flutter.

Questions ?


Attribution


About

This was for a DevICT (http://devict.org) presentation given July, 2020.

Topics

Resources

License

Stars

Watchers

Forks