Skip to content

Tips and tricks

Pierre Champion edited this page Oct 17, 2019 · 18 revisions

Collection of tips and tricks found by go-flutter users

As more and more peoples use flutter on the desktop, a multitude of small features are requested. It's not very clear whether, or not some of those features should be incorporated into the go-flutter source code as a reminder of a list was created to keep track of those requests and potential solutions.
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 of the 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),
	)
}

By @Drakirus, #267.

3. Open the Virtual keyboard on text edit:

Place the following virtual_keyboard_linux.go file into the go/cmd/ directory:

package main

// the file virtual_keyboard_linux.go is used to show the 'onboard'
// vitrual keyboard upon text input.
// LINUX only, variants (i.e.: *_windows.go) needs to be created.

import (
	"os/exec"
	flutter "github.com/go-flutter-desktop/go-flutter"
)

var onBoard = exec.Command("onboard")

func init() {
	options = append(options,
		flutter.VirtualKeyboardShow(func(){
			err := onBoard.Start()
			if err != nil {
				return
			}
		}),
	)
}

By @Drakirus, #274.