@@ -18,7 +18,9 @@ class MobileUnityWidgetController extends UnityWidgetController {
1818 /// used for cancel the subscription
1919 StreamSubscription ? _onUnityMessageSub,
2020 _onUnitySceneLoadedSub,
21- _onUnityUnloadedSub;
21+ _onUnityUnloadedSub,
22+ _onUnityAttachedSub,
23+ _onUnityDetachedSub;
2224
2325 MobileUnityWidgetController ._(this ._unityWidgetState,
2426 {required this .unityId}) {
@@ -30,11 +32,12 @@ class MobileUnityWidgetController extends UnityWidgetController {
3032 /// in [UnityWidget.onUnityCreated] callback.
3133 static Future <MobileUnityWidgetController > init (
3234 int id, MobileUnityWidgetState unityWidgetState) async {
33- await UnityWidgetPlatform .instance.init (id);
34- return MobileUnityWidgetController ._(
35+ final controller = MobileUnityWidgetController ._(
3536 unityWidgetState,
3637 unityId: id,
3738 );
39+ await UnityWidgetPlatform .instance.init (id);
40+ return controller;
3841 }
3942
4043 @visibleForTesting
@@ -66,6 +69,22 @@ class MobileUnityWidgetController extends UnityWidgetController {
6669 .onUnityUnloaded (unityId: unityId)
6770 .listen ((_) => _unityWidgetState.widget.onUnityUnloaded !());
6871 }
72+
73+ if (_unityWidgetState.widget.onUnityAttached != null ) {
74+ _onUnityAttachedSub = UnityWidgetPlatform .instance
75+ .onUnityAttached (unityId: unityId)
76+ .listen ((_) {
77+ _unityWidgetState.widget.onUnityAttached !();
78+ });
79+ }
80+
81+ if (_unityWidgetState.widget.onUnityDetached != null ) {
82+ _onUnityDetachedSub = UnityWidgetPlatform .instance
83+ .onUnityDetached (unityId: unityId)
84+ .listen ((_) {
85+ _unityWidgetState.widget.onUnityDetached !();
86+ });
87+ }
6988 }
7089
7190 /// Checks to see if unity player is ready to be used
@@ -200,10 +219,14 @@ class MobileUnityWidgetController extends UnityWidgetController {
200219 _onUnityMessageSub? .cancel ();
201220 _onUnitySceneLoadedSub? .cancel ();
202221 _onUnityUnloadedSub? .cancel ();
222+ _onUnityAttachedSub? .cancel ();
223+ _onUnityDetachedSub? .cancel ();
203224
204225 _onUnityMessageSub = null ;
205226 _onUnitySceneLoadedSub = null ;
206227 _onUnityUnloadedSub = null ;
228+ _onUnityAttachedSub = null ;
229+ _onUnityDetachedSub = null ;
207230 }
208231
209232 void dispose () {
0 commit comments