1. Project Overview & Quickstart (go-flutter-desktop/go-flutter)
File: README.md
go-flutter - A package that brings Flutter to the desktop
Purpose
Flutter allows you to build beautiful native apps on iOS and Android from a single codebase.
This unofficial project brings Flutter to the desktop through the power of Go and GLFW.
The flutter engine itself doesn't know how to deal with desktop platforms (eg handling mouse/keyboard input). Instead, it exposes an abstraction layer for whatever platform to implement. This project implements the Flutter's Embedding API using a single code base that runs on Windows, macOS, and Linux. For rendering, GLFW fits the job because it provides the right abstractions over the OpenGL's Buffer/Mouse/Keyboard for each platform.
The choice of Golang comes from the fact that it has the same tooling on every platform. Plus Golang is a great language because it keeps everything simple and readable, which makes it easy to build cross-platform plugins.
Getting started
The best way to get started is to install hover, the official go-flutter tool to set up, build and run Flutter apps on the desktop, including hot-reload.
Read the hover tutorial to run your app on the desktop, or start with one of our example apps.
If you want more in-depth information about go-flutter, read the wiki.
Supported features
- Linux :penguin:
- MacOS :apple:
- Windows :checkered_flag:
- Hot Reload
- Plugin system
- BinaryMessageCodec, BinaryMessageChannel
- StandardMessageCodec, JSONMessageCodec
- StandardMethodCodec, MethodChannel
- Plugin detection for supported plugins
- Importable as Go library into custom projects
- UTF-8 Text input
- Clipboard copy & paste
- Window title and icon
- Standard keyboard shortcuts
- ctrl-c ctrl-v ctrl-x ctrl-a
- Home End shift-Home shift-End
- Left ctrl-Left ctrl-shift-Left
- Right ctrl-Right ctrl-shift-Right
- Backspace ctrl-Backspace Delete
- Mouse-over/hovering
- Mouse-buttons
- RawKeyboard events
- Distribution format (windows-msi, mac-dmg, linux-appimage, and more)
- Cross-compiling using docker :whale:
Are you missing a feature? Open an issue!
Examples
A separate repository contains example Flutter apps that also run on the desktop. Go to github.com/go-flutter-desktop/examples to give them a try.
Plugins
Some popular plugins are already implemented over at github.com/go-flutter-desktop/plugins.
If you have implemented a plugin that you would like to share, feel free to open a PR on the plugins repository!
For a detailed tutorial on how to create a plugin, read the wiki.
Version compatibility
Flutter version
Flutter itself is a relatively young project. Its framework and engine are updated often. The go-flutter project tries to stay compatible with the beta channel of Flutter.
Go version
Updating Go is simple and Go seldomly has backwards-incompatible changes. This project remains compatible with the latest Go stable release.
GLFW version
This project uses go-gl/glfw for GLFW v3.3.
License
File: embedder/README.md
embedder
This package wraps the Flutter embedder API in Go and adds some helper functions to work with it. This package does NOT contain any platform specific code (glfw, etc.) and may eventualy be used for platforms other than the ones targeted by go-flutter right now. Note that this package does not promise a stable API: types, functions, methods may all change in a breaking way.
Build
To build this package set the CGO_LDFLAGS and run go build. For example:
On Linux:
export CGO_LDFLAGS="-L${HOME}/.cache/hover/engine/linux/"
go buildTo build this package on Mac OS
export CGO_LDFLAGS="-F ${HOME}/Library/Caches/hover/engine/darwin"
go buildTo build this package on Windows
set CGO_LDFLAGS="-L%HOMEPATH%/.cache/hover/engine/windows/"
go buildThis works if hover has cached the flutter engine for the local user.
2. Official Technical Reference & Guides (go-flutter-desktop/website)
File: README.md
hover.build website
This repository contains the source for the hover.build website.
Additions are welcome. Feel free to open an issue if you want to discuss your idea before working on a PR.
Developing
Install hugo and run hugo serve --cleanDestinationDir to test local changes before opening a PR.
Theme
The themes folder contains a slightly modified copy of the kube theme.
Hosting
The site is manually deployed and served with love by Caddy on sherlock4.geertjohan.net.
File: content/faq/_index.md
+++
title = "FAQ"
description = "Asked and answered"
+++
How does this compare to the "official" flutter desktop?
A elaborate answer was given in issue#191.
Is hover compatible with Visual Studio Code?
Yes, more details available in issue#129.
Is hover compatible with Android Studio?
No, the flutter-intellij plugin doesn't support attaching to existing process,
issue#213.
Where can I find example of go-flutter plugins?
On our examples, we shared
multiples plugins implementations. They are easy to explore and run.
For more sophisticate plugins, look at our plugins repo.
File: content/docs/fonts.md
+++
title = "Fonts"
description = "Configure fonts for desktop"
weight = 30
toc = true
bref = "Fonts style your application, but how to use fonts on desktop? This guide walks you thorugh setting up fonts for desktop"
+++
Fonts are assets
Question: What is the issue with fonts and cross-platform?
Answer: No text visible? Make sure you have used fonts added to the project asset.
The default font for MaterialApp, Roboto, is not installed on all machines.
Example
If the host is missing some fonts, it can cause the text to not be rendered or worse the app might crash, the
the pointer_demo
solves this issue by including the fonts as asset.
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Code Sample for widgets.Listener',
theme: ThemeData(
// If the host is missing some fonts, it can cause the
// text to not be rendered or worse the app might crash.
fontFamily: 'Roboto',
primarySwatch: Colors.blue,
),
home: MyStatefulWidget(),
);
}
}# [...]
flutter:
fonts:
- family: Roboto
fonts:
- asset: fonts/Roboto/Roboto-Thin.ttf
weight: 100
- asset: fonts/Roboto/Roboto-Light.ttf
weight: 300
- asset: fonts/Roboto/Roboto-Regular.ttf
weight: 400
- asset: fonts/Roboto/Roboto-Medium.ttf
weight: 500
- asset: fonts/Roboto/Roboto-Bold.ttf
weight: 700
- asset: fonts/Roboto/Roboto-Black.ttf
weight: 900Directory structure
.
โโโ pubspec.yaml
โโโ fonts
โโโ Roboto
โโโ LICENSE.txt
โโโ Roboto-Black.ttf
โโโ Roboto-Bold.ttf
โโโ Roboto-Light.ttf
โโโ Roboto-Medium.ttf
โโโ Roboto-Regular.ttf
โโโ Roboto-Thin.ttfFile: content/docs/quick-start.md
+++
title = "Quick Start"
description = "Up and running in under a minute"
weight = 10
toc = true
bref = "Hover is a simple build tool to create 'go-'flutter desktop applications"
+++
Install
Hover uses Go to build your Flutter application to desktop. Hover itself is also written using the Go language. You will need to install go on your development machine.
Then install hover like this:
go get -u github.com/go-flutter-desktop/hoverIf you get this error: cmdApp.ProcessState.ExitCode undefined (type *os.ProcessState has no field or method ExitCode),
then update Go to at least version 1.12.
Run the same command to update when a newer version becomes available.
Install these dependencies:
You need to make sure you have a C compiler.
The recommended C compiler are documented here.You need to make sure you have dependencies of GLFW:
- On macOS, you need Xcode or Command Line Tools for Xcode (
xcode-select --install) for required headers and libraries. - On Ubuntu/Debian-like Linux distributions, you need
libgl1-mesa-dev xorg-devpackages. - On CentOS/Fedora-like Linux distributions, you need
libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel mesa-libGL-devel libXi-develpackages. - See here for full details.
- On macOS, you need Xcode or Command Line Tools for Xcode (
Init
The first time you use hover for a project, you'll need to initialize the project for desktop. hover init requires a project path. This is usualy the path for your project on github or a self-hosted git service. If you are unsure, just make something up, it can always be changed later.
First, cd into a flutter project.
cd projects/simpleApplicationhover init github.com/my-organization/simpleApplicationThis creates the directory desktop and adds boilerplate files such as Go code and a default logo.
Make sure you have the following
main_desktop.dart
in the root librairie of your application.
Optionally, you may add plugins to desktop/cmd/options.go
Optionally, change the logo in desktop/assets/logo.png, which is used as icon for the window.
Run with hot-restart
To run the application and attach flutter for hot-reload support:
hover runBy default, hover uses the file lib/main_desktop.dart as entrypoint. You may specify a different endpoint by using the --target flag.
The hot-reload is manual because you'll need to press 'r' in the terminal to hot-reload the application.
If you want to integrate go-flutter with VSCode, read this issue.
File: content/docs/using-plugins.md
+++
title = "Using plugins"
description = "Plugins "
weight = 30
bref = "Plugins allow flutter applications to communicate with the host platform"
+++
Plugins are an important part when building applications that interact with the
host system. This guide explains how to use plugins across Android, iOS and
desktop with Hover.
The github wiki about using plugins is a good source of updated information.
File: content/blog/one-year-in.md
title: "go-flutter: One Year In, What was the journey like?" The go-flutter project is now one year old. We want to let you know how the project has evolved over this past year. date: 2019-08-17T19:19:27+02:00 categories: ["general"] weight: 20 author: "Pierre Champion (@Drakirus)" draft: false
I'm very excited to use this first post to talk about go-flutter, what it is, why it was created, and how it has evolved.
Before I explain what go-flutter is, let's start with the famous flutter system overview.
Flutter's engine takes core technologies, Skia, a 2D graphics rendering library, and Dart, and hosts them in a shell. Different platforms have different shells; for example, there are shells available for Android and iOS.
The Flutter team also exposes an embedder API which allows Flutter's engine to be used as a library.
The go-flutter project provides a shell that implements the embedder APIs using a single code base that runs on Windows, macOS, and Linux. Achieving cross-platform support from a single codebase was made easy by using Go as the primary programming language.
As the title says, this project was created a year ago, at that time, the embedder API was composed of 180 lines of C. To begin with, I wanted to reproduce a simple example shell created by @chinmaygarde, one of the core maintainer of the Flutter engine. At first, my goal was to learn the Golang programming language, but only after the first commit, I realized that my approach had some advantage over FDE:
- A single codebase for all desktops, instead of 3.
(Doesn't this remind you one of Flutter main selling point? ๐). - At that time the Windows platform didn't support text input.
FDE is now part of the flutter project, making it the official desktop shell.
I was having fun, so I kept going, implementing features after feature. (Mostly by reproducing what @stuartmorgan added to FDE).
Fast forward six months later, I was having trouble with my studies/work/go-flutter/life balance, don't get me wrong, I did receive fantastic input from the community, but it was too much work, the embedder API was growing fast (it now has over 1100 LOC) and my poor Golang architectures decision started to become a burden.
That's when @GeertJohan showed up and joined the project. We moved the project to an organization and began fixing architecture issues. Support for flutter platform channels codecs/API was implemented, along with support for plugins.
The Hover tool was created to make building go-flutter applications easier.
Additionally, We also had minor input into the Flutter engine project. With go-flutter, we created a reliable unofficial shell that is used by dozens of users. We hope to create better consensus on desktop shells, differences between go-flutter and FDE were found and aligned, which is good. Interaction/discussion between different official/unofficial projects shapes the 'Google-controlled' part of the Flutter project.
Overall, I'm very proud of what the project has become. I qualify the project to be very mature. We are now a real alternative to the official desktop shells, with a different approach. Our primary selling points are:
- Easy plugins writing, it is more accessible (and by the nature of Golang, more maintainable) in go-flutter than on the official project.
- Single code-base for windows/mac/linux applications.
- Less dependencies.
We'd like to thank everyone who has contributed to the project so far. Many people have helped us, not just by writing code but also by testing new features, reporting bugs, giving advice or sharing ideas. Also a big shout-out to the maintainers of the Flutter Engine project who've helped us out and shared their feedback. Thanks!
We hope to write more about go-flutter in future posts, to give you updates on the project.