Skip to content

Tips and tricks

Pierre Champion edited this page Sep 25, 2019 · 18 revisions

Collection of tips and tricks found by go-flutter users

This list may be converted to go-flutter Option or plugins.

1. Windows console

On the Windows OS, the console keep showing and disappearing when using Dart Process?

Place the following hide-cmd_windows.go file into the go/cmd/ directory:

package main

// the file hide-cmd_windows.go is used to hide console windows that keep
// showing up on each Dart Process.run calls

import "github.com/gonutz/w32"

func init() {
	console := w32.GetConsoleWindow()
	if console != 0 {
		_, consoleProcID := w32.GetWindowThreadProcessId(console)
		if w32.GetCurrentProcessId() == consoleProcID {
			w32.ShowWindowAsync(console, w32.SW_HIDE)
		}
	}
}

Found by @Tokenyet.

2. Set the initial window dimension based on screen resolution

Place the following window-size-based-on-resolution.go file into the go/cmd/ directory:

package main

// the file window-size-based-on-resolution.go is used to set the initial
// dimension of the window based on screen resolution.
//
// The following example sets the window to take all to monitor screen minus
// a border.

import (
	flutter "github.com/go-flutter-desktop/go-flutter"
	"github.com/go-gl/glfw/v3.2/glfw"
)

const windowBorder = 100

func init() {
	// Notice: Code in init() delays first frame!

	// Not best practice, you should let go-flutter make this call.
	err := glfw.Init()
	if err != nil {
		panic(err)
	}

	vidMoce := glfw.GetPrimaryMonitor().GetVideoMode()

	options = append(options,
		flutter.WindowInitialDimensions(
			vidMoce.Width-windowBorder*2,
			vidMoce.Height-windowBorder*2,
		))
	options = append(options,
		flutter.WindowInitialLocation(windowBorder, windowBorder),
	)
}