Skip to content

Commit

Permalink
Fix call order created init + detached on dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortes committed Dec 19, 2022
1 parent d8ede98 commit ac66ba0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/src/io/mobile_unity_widget_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class MobileUnityWidgetController extends UnityWidgetController {
unityWidgetState,
unityId: id,
);
await UnityWidgetPlatform.instance.init(id);
return controller;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/src/io/unity_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class _UnityWidgetState extends State<UnityWidget> {

@override
Future<void> dispose() async {
widget.onUnityDetached?.call();
if (!kIsWeb) {
if (_nextUnityCreationId > 0) --_nextUnityCreationId;
}
Expand Down Expand Up @@ -199,6 +200,8 @@ class _UnityWidgetState extends State<UnityWidget> {
final controller = await MobileUnityWidgetController.init(id, this);
_controller = controller;
widget.onUnityCreated(controller);
await UnityWidgetPlatform.instance.init(id); // init is called here so onCreated called before onAttached


// if (widget.onUnityAttached != null)
// widget.onUnityAttached!();
Expand Down
3 changes: 3 additions & 0 deletions lib/src/web/web_unity_widget_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class WebUnityWidgetController extends UnityWidgetController {

MethodChannel? _channel;

@override
int get id => throw UnimplementedError("Platform does not support id");

/// used for cancel the subscription
StreamSubscription? _onUnityMessageSub,
_onUnitySceneLoadedSub,
Expand Down

0 comments on commit ac66ba0

Please sign in to comment.