flutter

package module
v0.4.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2019 License: BSD-3-Clause Imports: 13 Imported by: 53

README

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 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.

How to install

:package: :penguin: Linux

From binaries

Check out the Release page for prebuilt versions.

From source

Go read first: go-gl/glfw

# Clone
git clone https://github.com/go-flutter-desktop/go-flutter.git
cd go-flutter

# Build the flutter simpleDemo project
cd example/simpleDemo/
cd flutter_project/demo/
flutter build bundle
cd ../..

# Download the share library, the one corresponding to your flutter version.
go run engineDownloader.go

# REQUIRED before every `go build`. The CGO compiler need to know where to look for the share library
export CGO_LDFLAGS="-L${PWD}"
# The share library must stay next to the generated binary.

# Get the libraries
go get -u -v github.com/go-flutter-desktop/go-flutter

# Build the example project
go build main.go

# `go run main.go` is not working ATM.
:package: :checkered_flag: Windows

From binaries

Check out the Release page for prebuilt versions.

From source

Go read first: go-gl/glfw

# Clone
git clone https://github.com/go-flutter-desktop/go-flutter.git
cd go-flutter

# Build the flutter simpleDemo project
cd example/simpleDemo/
cd flutter_project/demo/
flutter build bundle
cd ../..

# Download the share library, the one corresponding to your flutter version.
go run engineDownloader.go

# REQUIRED before every `go build`. The CGO compiler need to know where to look for the share library
set CGO_LDFLAGS=-L%cd%
# The share library must stay next to the generated binary.
# If you ran into a MinGW ld error, checkout: https://github.com/go-flutter-desktop/go-flutter/issues/34

# Get the libraries
go get -u -v github.com/go-flutter-desktop/go-flutter

# Build the example project
go build main.go

# `go run main.go` is not working ATM.
:package: :apple: MacOS

From binaries

Check out the Release page for prebuilt versions.

From source

Go read first: go-gl/glfw

# Clone
git clone https://github.com/go-flutter-desktop/go-flutter.git
cd go-flutter

# Build the flutter simpleDemo project
cd example/simpleDemo/
cd flutter_project/demo/
flutter build bundle
cd ../..

# Download the share library, the one corresponding to your flutter version.
go run engineDownloader.go

# REQUIRED before every `go build`. The CGO compiler need to know where to look for the share library
export CGO_LDFLAGS="-F${PWD} -Wl,-rpath,@executable_path"
# The share library must stay next to the generated binary.

# Get the libraries
go get -u -v github.com/go-flutter-desktop/go-flutter

# Build the example project
go build main.go

# `go run main.go` is not working ATM.

Flutter Demos Projects

The examples are available here.

Screenshot of the Stocks demo app on macOS

Version compatibility

Flutter version

Flutter is a relatively new project. It's framework and engine are updated often. This 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.2.

Support

  • Linux 🐧
  • Windows 🏁
  • MacOS 🍎
  • Importable go library
  • Plugins Medium article on how the Flutter's messaging works
    • JSON MethodChannel
    • StandardMethodCodec, ...
  • System plugins Platform channels used by the Flutter system
    • Window Title
    • Text input
    • Clipboard (through shortcuts and UI)
    • 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
      • ctrl-Delete
    • Key events

Documentation

Index

Constants

View Source
const (
	ModNone         int = 0
	ModShift        int = 1
	ModControl      int = 2
	ModShiftControl int = 3
	ModAlt          int = 4
	ModShiftAlt     int = 5
	ModSuper        int = 8
	ModShiftSuper   int = 9
)

Modifier keys from glfw

Variables

View Source
var KeyboardAzertyLayout = KeyboardShortcuts{
	Cut:       glfw.KeyX,
	Copy:      glfw.KeyC,
	Paste:     glfw.KeyV,
	SelectAll: glfw.KeyQ,
}

KeyboardAzertyLayout gives an Azerty layout (french)

View Source
var KeyboardQwertyLayout = KeyboardShortcuts{
	Cut:       glfw.KeyX,
	Copy:      glfw.KeyC,
	Paste:     glfw.KeyV,
	SelectAll: glfw.KeyA,
}

KeyboardQwertyLayout is the default key for shortcuts (US-layout)

Functions

func Run

func Run(options ...Option) (err error)

Run executes a flutter application with the provided options. given limitations this method must be called by the main function directly.

Types

type ArgsAppSwitcherDescription

type ArgsAppSwitcherDescription struct {
	Label        string `json:"label"`
	PrimaryColor int64  `json:"primaryColor"`
}

ArgsAppSwitcherDescription Args content

type KeyboardShortcuts

type KeyboardShortcuts struct {
	Cut       glfw.Key
	Copy      glfw.Key
	Paste     glfw.Key
	SelectAll glfw.Key
}

KeyboardShortcuts Struct where user can define his own keyboard shortcut. This will allow application to support keyboard layout different from US layout

type Option

type Option func(*config)

Option for gutter

func ApplicationICUDataPath

func ApplicationICUDataPath(p string) Option

ApplicationICUDataPath specify the path to the ICUData.

func ApplicationWindowDimension

func ApplicationWindowDimension(x int, y int) Option

ApplicationWindowDimension specify the startup's dimention of the window.

func OptionAddPluginReceiver

func OptionAddPluginReceiver(handler PluginReceivers, channelName string) Option

OptionAddPluginReceiver add a new function that will be trigger when the FlutterEngine send a PlatformMessage to the Embedder

func OptionKeyboardLayout

func OptionKeyboardLayout(keyboardLayout KeyboardShortcuts) Option

OptionKeyboardLayout allow application to support keyboard that have a different layout when the FlutterEngine send a PlatformMessage to the Embedder

func OptionPixelRatio

func OptionPixelRatio(ratio float64) Option

OptionPixelRatio forces the the scale factor for the screen. By default, go-flutter will calculate the correct pixel ratio for the user, based on their monitor DPI. Setting this option is not advised.

func OptionVMArguments

func OptionVMArguments(a []string) Option

OptionVMArguments specify the arguments to the Dart VM.

func OptionWindowInitializer

func OptionWindowInitializer(ini func(*glfw.Window) error) Option

OptionWindowInitializer allow initializing the window.

func ProjectAssetPath

func ProjectAssetPath(p string) Option

ProjectAssetPath specify the flutter assets directory.

func ProjectAssetsPath

func ProjectAssetsPath(p string) Option

ProjectAssetsPath specify the flutter assets directory.

func WindowIcon

func WindowIcon(iconProivder func() ([]image.Image, error)) Option

WindowIcon sets an icon provider func, which is called during window initialization. For tips on the kind of images to provide, see https://godoc.org/github.com/go-gl/glfw/v3.2/glfw#Window.SetIcon

type PluginReceivers

type PluginReceivers func(
	message *embedder.PlatformMessage,
	flutterEngine *embedder.FlutterEngine,
	window *glfw.Window,
) bool

PluginReceivers do stuff when receiving Message from the Engine, send result with `flutterEngine.SendPlatformMessageResponse`

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL