- âś… Know golang
- âś… Have introductory knowledge of MVVM, MVC, MVP, etc (UI development)
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
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.
-
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 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.
- GTK https://github.com/gotk3/gotk3
- desktop focused
- Nuklear https://github.com/golang-ui/nuklear
- desktop focused
- Fyne https://github.com/fyne-io/fyne
- basic mobile implementation (lacks sensor data, etc)
- QT https://github.com/therecipe/qt
- fairly complete mobile implementation
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
-
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
-
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.
---
Yes, mostly.
Limitations:
- Go mobile lacks some features
- not all packages are compatible, and assume a desktop environment
-
Flutter FFI (c/c++ engine)
-
Flutter Embedders
-
Go-Flutter Summary
-
Comparison to official flutter bindings
-
Golang GLFW layer
- Essentially go-flutter at its core is just ~ 200 lines of code to compile to C byte code with GLFW support
- This is not complex, at an implementation level, just fancy tooling
- see https://github.com/go-flutter-desktop/go-flutter/tree/640dcea647f47ceca0e3fb67166d2ea124a09f24
- All API's going to future flutter versions are deprecated but still functional
- ANY currently working features will not break.
- Go here for more information on flutter API versioning and compatibility policy
- Install go 1.13+
- instructions can be found at https://golang.org/doc/install
- Install flutter
- instructions can be found at https://flutter.dev/docs/get-started/install
- Install go-flutter
- install hover (flutters unofficial go client)
GO111MODULE=on go get -u -a github.com/go-flutter-desktop/hover
- install hover (flutters unofficial go client)
- Install dependencies
- mac - have xcode installed
- linux - install the following packages 'libgl1-mesa-dev xorg-dev'
- windows - install gflw for windows https://www.glfw.org/docs/latest/compile.html#compile_deps
- Enable desktop builds
flutter config --enable-macos-desktop flutter config --enable-linux-desktop flutter config --enable-windows-desktop
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
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
What is a "plugin" ?
- It sounds fancy, but it's just an interface between go & dart.
https://github.com/go-flutter-desktop/examples/tree/master/plugin_tutorial/go-plugin-example/complex
- Go to golang_flutter_demo directory
- Run and build the app
hover run
Lets see what it takes to run this.
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
}
Add package
go/cmd/options.go
flutter.AddPlugin(&image_editor.Editor{}),
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);
- 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
- Checkout the golang_flutter_demo repo
- Add a different image editing feature from the provided image package
- Test the go-flutter build system and see if it's right for you.
- ???
- Become a hermit for the weekend and make a really cool app with go-flutter.
- https://github.com/flutter/flutter
- https://github.com/go-flutter-desktop/go-flutter
- https://github.com/anthonynsimon/bild