A port of Flutter to Go v1.18.0

Flutter's widgets. Written in Go.

Glutter is a port of Flutter to Go. It gives Go the framework API of Flutter. Widgets, state, gestures, animation, Material 3 and Cupertino have the names you know, and they are drawn by Glutter's own engine on the GPU.

Get started I know Flutter GitHub

go get github.com/rm4n0s/glutter@latest
A picture of the app Showcase

This is the app, not a picture of it. It is a Go program, compiled to WebAssembly.

6

platforms from one code base

0

lines of C to compile on the desktop and the web

400 fps

with a million triangles and their edges, on a Radeon RX 6800M

17

apps of the Playground run in this site

One code base, six platforms

  • LinuxVulkan, OpenGL ES
  • WindowsDirect3D 12
  • macOSMetal
  • iOSMetal
  • AndroidVulkan
  • WebWebGPU, WebGL 2
  • The API you know

    StatefulWidget, BuildContext, SetState, ThemeOf, Navigator, animation controllers, CustomPaint. What you know of Flutter carries over, name by name.

  • Only Go

    There is no cgo on the desktop and the web. CGO_ENABLED=0 go build makes the app, and Go is all you install: no C compiler, no SDK, no other tool.

  • An engine of its own

    It is not Flutter’s engine, and it is not a web view. Glutter lays out, paints and draws with the GPU itself, through Vulkan, Direct3D 12, Metal, WebGPU and WebGL 2.

If you know Flutter, you can read this

A constructor is a function NewX. Required parameters are arguments, optional ones are fields of XOpts, and State<Counter> is m.StateOf[*Counter]. A few rules like these turn the whole API into Go.

Flutter, in Dart
class Counter extends StatefulWidget {
  const Counter({super.key});
  @override
  State<Counter> createState() => _CounterState();
}

class _CounterState extends State<Counter> {
  int _count = 0;

  @override
  Widget build(BuildContext context) {
    return TextButton(
      onPressed: () => setState(() => _count++),
      child: Text('Pushed $_count times'),
    );
  }
}
Glutter, in Go
type Counter struct{ m.StatefulWidget }

func NewCounter() *Counter { return &Counter{} }

func (c *Counter) CreateState() m.State {
	return &counterState{}
}

type counterState struct {
	m.StateOf[*Counter]
	count int
}

func (s *counterState) Build(bc m.BuildContext) m.Widget {
	return m.NewTextButton(
		func() { s.SetState(func() { s.count++ }) },
		m.NewText("Pushed "+strconv.Itoa(s.count)+" times"))
}

Glutter for Flutter developers: all the rules, side by side

Drawn by Go, at every frame

These are not videos. Each one is a Go program that runs in this page when you press Run.

Charts with no chart library

The line with its glow, the ring and the bars are custom painters, about 200 lines of Go. Change the period, and every shape moves to its new values.

What to try in Pulse, a dashboard

  • A painter listens to an animation controller, and no widget is built again while it moves
  • Gradients, blur, arcs and curves, with the Canvas of Flutter
  • The mouse over the line shows the value under it
A picture of the app Pulse, a dashboard

Thousands of particles

A loop in Go moves every particle, and one painter draws them all, sixty times a second. The pointer pulls them, and a click pushes them away.

What to try in Flow, a field of particles

  • 4,000 particles at the start, and up to 8,000 with the slider
  • Light that adds up where the lines cross
  • Material widgets over the picture, in the same widget tree
A picture of the app Flow, a field of particles

3D is part of the toolkit

A 3D view is a widget. It shows glTF models with their materials, skins and shadows, has a camera you can orbit, and sits in the tree beside buttons and sliders. A program can also draw with shaders of its own.

Two looks

The Material 3 components and the Cupertino ones of iOS and macOS are both there, in light and in dark. An app chooses the one it wants.

Test a screen without a window

gluttertest runs a widget on a fake platform, as Flutter’s WidgetTester does: it builds the app, taps what a finder finds, lets time pass and compares a screen with a golden image. The tests of the apps of this page run in well under a second, with go test.

func TestTapIncrements(t *testing.T) {
	ts := gluttertest.New(t)
	ts.PumpWidget(NewMyApp())

	ts.Tap(gluttertest.ByType[*m.FloatingActionButton]())
	ts.Pump(50 * time.Millisecond)

	if n := ts.Count(gluttertest.ByText("1")); n != 1 {
		t.Errorf("the text 1 is shown %d times, want 1", n)
	}
}

Run them all

The Playground

Applications built with Glutter

My own desktop applications use it every day.

Under the hood#

Glutter is a port of Flutter’s framework, written again in Go. It runs on its own engine, not on Flutter’s. On Linux that is a Wayland and X11 platform layer and a Vulkan renderer with an OpenGL ES 3.0 fallback. On Windows it uses Win32 and Direct3D 12, and on macOS and iOS it uses AppKit, UIKit and Metal. In a browser the same Go code is compiled with GOOS=js GOARCH=wasm by the standard Go toolchain, and draws with WebGPU or WebGL 2.

The system libraries are called through purego, and text is laid out with go-text. Android is the one target that uses cgo, for the NDK.

Apps import one package, the way Flutter’s apps import material.dart:

import m "github.com/rm4n0s/glutter/material"
Language
Go
Runs on
Linux, macOS, Windows, Web, Android, iOS
License
BSD-3-Clause
Version
v1.18.0

Guides for Glutter

Start with one command

You need Go 1.27.4 or newer, and nothing else to build.

Write your first Glutter app The whole guide

# Add Glutter to your module
$ go get github.com/rm4n0s/glutter@latest
# Run your app in a window
$ go run .
# Or in a browser
$ go run github.com/rm4n0s/glutter/cmd/glutter-web serve .