Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Prepare to revert Flutter 3.0 PlatformView workaround #667

Closed
timbotimbo opened this issue Jul 28, 2022 · 4 comments · Fixed by #685
Closed

[Android] Prepare to revert Flutter 3.0 PlatformView workaround #667

timbotimbo opened this issue Jul 28, 2022 · 4 comments · Fixed by #685
Labels
android This issue is specific to the Android Platform. important info This refers to important information

Comments

@timbotimbo
Copy link
Collaborator

timbotimbo commented Jul 28, 2022

Description

Flutter 3.0 broke the default android platformview (#584), rendering the unity widget in the wrong location.
According to flutter/flutter#103630 (comment), this is now fixed in Flutter beta releases.

If the original issue is fixed, we can remove the workaround in this plugin.
And if we prepare and test this now, it can be ready to go when theses fixes make it into a new Flutter release.

Current workaround

@juicycleff fixed this in flutter_unity_widget 2022.1.1 by ignoring useAndroidSurfaceView and always using initExpensiveAndroidView.

/* /lib/src/io/device_method.dart */

// commented for 3.0.0 changes in platform view rendition
// if (!useAndroidViewSurface) {
//   return AndroidView(
//     viewType: _viewType,
//     onPlatformViewCreated: onPlatformViewCreated,
//     gestureRecognizers: gestureRecognizers,
//     creationParams: creationParams,
//     creationParamsCodec: const StandardMessageCodec(),
//     hitTestBehavior: PlatformViewHitTestBehavior.opaque,
//     layoutDirection: TextDirection.ltr,
//   );
// }

/* return initExpensiveAndroidView below */

This works for now, but the ExpensiveAndroidView introduces new bugs that did not happen with Flutter 2.x.

Flutter beta

The current Flutter beta releases (starting with 3.3.0-0.0.pre) seem to fix the original issue, meaning we can enable the AndroidView option again.

Setup:

  • Flutter 3.0.5 & 3.3.0-0.0.pre
  • Unity 2021.3.5
  • flutter_unity_widget 2022.1.7+1 (With the above code uncommented)
  • Android 12 (Samsung Galaxy S20FE)

In these videos I open the 'Simple Unity Demo' and 'Native exposed API demo' screens because these show the original issue the best.

Flutter 3.0.5
useAndroidSurfaceView: false
Flutter 3.3.0-0.0.pre
useAndroidSurfaceView: false
Flutter 3.3.0-0.0.pre
useAndroidSurfaceView: true
3.0.5.mp4
3.3.0-0.0.pre.mp4
3.3.0-0.0.pre.v2.mp4

Result

Flutter 3.3.0-0.0-pre seems to fix the issue, so we should enable AndroidView again when this makes it to a Flutter release version.
In this way users get to choose which type of PlatformView to use, and might be able to avoid certain bugs,

It also shows that useAndroidViewSurface: false now respects the margin and rounded borders that are broken with useAndroidViewSurface: true

[UPDATE] Testing

I tried some more devices to check android compatibility with 3.3.0-0.0.pre:

Device Android useAndroidViewSurface: false useAndroidViewSurface: true
Samsung Galaxy S20FE 12 Works Works
Samsung Galaxy S8 9 Works Works
Wileyfox Swift 7.1 Works broken
Samsung Galaxy J5 6 Works broken
@Cheong43
Copy link

Cheong43 commented Aug 12, 2022

Uncomment the !useAndroidViewSurfacecondition mentioned above

Device Android useAndroidViewSurface: false useAndroidViewSurface: true
Samsung Galaxy S10 12 Works broken
pixel 4a 11 Works Works
Moto g30 11 Works broken

Also, ifuseAndroidViewSurface: true and using unityWidget in Page 1, and push()to Page 2, if using image_picker or leaving the app on Page 2, the unity view will unexpectedly be invoked(#649 , #637 ...)

But these bugs no longer exist with usingPlatformView. (Run on flutter 3.3.0 pre)

@Cheong43
Copy link

I found it interesting that AndroidViewSurface works perfectly in google pixel 4a and pixel 6 without any config, and has a 120% improvement on fps and better power dissipation performance than using PlatformView. Maybe google has done some native optimization on pixel phone?

But PlatformViewfit most situations, it's more reliable in my case.

@timbotimbo
Copy link
Collaborator Author

@juicycleff @Ahmadre Flutter 3.3.0 is now live with the fix included.

@juicycleff
Copy link
Owner

@timbotimbo this is great news, was looking at it myself. Will test done more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android This issue is specific to the Android Platform. important info This refers to important information
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants