Skip to content

Commit ca3710e

Browse files
committed
feat: changes the inital flutter route
fixes: /issues/276
1 parent 72a54d7 commit ca3710e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

application.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/go-flutter-desktop/go-flutter/embedder"
1414
"github.com/go-flutter-desktop/go-flutter/internal/execpath"
1515
"github.com/go-flutter-desktop/go-flutter/internal/opengl"
16+
"github.com/go-flutter-desktop/go-flutter/plugin"
1617
)
1718

1819
// Run executes a flutter application with the provided options.
@@ -270,6 +271,16 @@ func (a *Application) Run() error {
270271
}
271272
}
272273

274+
// Change the flutter initial route
275+
initialRoute := os.Getenv("GOFLUTTER_ROUTE")
276+
if initialRoute != "" {
277+
defaultPlatformPlugin.flutterInitialized = func() {
278+
plugin.
279+
NewMethodChannel(messenger, "flutter/navigation", plugin.JSONMethodCodec{}).
280+
InvokeMethod("pushRoute", initialRoute)
281+
}
282+
}
283+
273284
// Setup a new windowManager to handle windows pixel ratio's and pointer
274285
// devices.
275286
windowManager := newWindowManager(a.config.forcePixelRatio)

platform.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ type platformPlugin struct {
1919
glfwTasker *tasker.Tasker
2020
window *glfw.Window
2121
channel *plugin.MethodChannel
22+
23+
// flutterInitialized gets called once flutter is running and ready
24+
// to process upstream plugin calls. (It usually takes ~10 rendering frame).
25+
flutterInitialized func()
2226
}
2327

2428
// hardcoded because there is no swappable renderer interface.
2529
var defaultPlatformPlugin = &platformPlugin{
26-
popBehavior: PopBehaviorNone,
30+
popBehavior: PopBehaviorNone,
31+
flutterInitialized: func() {},
2732
}
2833

2934
var _ Plugin = &platformPlugin{} // compile-time type check
@@ -104,5 +109,8 @@ func (p *platformPlugin) handleWindowSetTitle(arguments interface{}) (reply inte
104109
p.glfwTasker.Do(func() {
105110
p.window.SetTitle(appSwitcherDescription.Label)
106111
})
112+
113+
p.flutterInitialized()
114+
107115
return nil, nil
108116
}

0 commit comments

Comments
 (0)