flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

Add support for onDettached onAttach UnityWidget

Open Ortes opened this issue 1 year ago โ€ข 5 comments

Add support for onDettached onAttach UnityWidget to help setup and dispose Unity without loading a new scene

Description

I use the attached boolean in the FlutterUnityWidgetController to know if it is the the corresponding Widget is attached. When a UnityWidget is build it handles calling onAttached and onDetached on the Widgets which changed attached state. The last controller added in UnityPlayerUtils.controllers will be the one to be displayed (which correspond to the last one built).

I needed to change lib/src/io/mobile_unity_widget_controller.dart MobileUnityWidgetController._() constructor because the stream was not initialized before the event was sent so it was not caught. Only Android is supported for now.

Type of Change

  • [x] โœจ New feature (non-breaking change which adds functionality)
  • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
  • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] ๐Ÿงน Code refactor
  • [ ] โœ… Build configuration change
  • [ ] ๐Ÿ“ Documentation
  • [ ] ๐Ÿ—‘๏ธ Chore

Ortes avatar Dec 13 '22 12:12 Ortes

This looks handy but I think we could rework the api to match the new stream api for next release https://github.com/juicycleff/flutter-unity-view-widget/pull/733

juicycleff avatar Dec 16 '22 18:12 juicycleff

Yes I think this is a good idea I will rebase this on #733

Ortes avatar Dec 18 '22 14:12 Ortes

I introduced a small merge conflict by merging the null-safe example. It should only be the api_screen.dart file, and you can just keep all your current changes. So keep all the FlutterUnityController. calls instead of the 'newer' _unityWidgetController?. calls.

timbotimbo avatar May 07 '23 16:05 timbotimbo

@RoyalCoder88 Even though you've approved this, don't merge this before #733 is done. It contains commits (and new bugs) from that branch.

timbotimbo avatar Jun 04 '23 00:06 timbotimbo

@RoyalCoder88 Even though you've approved this, don't merge this before #733 is done. It contains commits (and new bugs) from that branch.

Okey just let me know when it's ready I will test it properly, thanks!

RoyalCoder88 avatar Jun 05 '23 16:06 RoyalCoder88