juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.13k stars 518 forks source link

How to structure the app to prevent duliplicated instances with router #822

Open proto-ziii opened 1 year ago

proto-ziii commented 1 year ago

Hi. I'm new to Flutter. And I wonder what is the recommended way to structure an app with the router and UnityWidget working simultaneously?

My goal is to have a single UnityWidget always fixed in the background, no matter how the router and overlay UI change. But currently, a new instance of UnityWidget will be created on router update and events such as onUnityMessage is duplicated.

I tried moving UnityWidget outside the router, but touch input on Unity won't work as it's also outside of the Scaffold.

Here is a simplified structure of my current app.

MaterialApp
└ Router
   └ Scaffold
      └ Stack
         ├ UnityWidget
         └ (other UI)

Thanks!