flutter_stripe icon indicating copy to clipboard operation
flutter_stripe copied to clipboard

CardField layout bug on Android 9(28)

Open AAkira opened this issue 2 years ago • 5 comments

Describe the bug

CardField not working on Android9.

screenshot-220628172912

To Reproduce

  1. Launch ThemeCardExample

Smartphone / tablet

  • Device: Pixel2
  • OS: Android 9
  • Package version: 3.1.0(curernt master)
  • Flutter version: 2.10.0

Additional context

It is also reproduced in the emulator.

  • CardFormField has the same bug

screenshot-220628173654

AAkira avatar Jun 28 '22 08:06 AAkira

Related flutter issues:

  • https://github.com/flutter/flutter/issues/106543
  • https://github.com/flutter/flutter/issues/104686

This bug seems to be caused by a destructive change in Flutter 3. Before API 29, transparent platform views do not work correctly.

It seems to be fixed if using initExpensiveAndroidView instead of initSurfaceAndroidView here. (Please note that this method is only available in Flutter 3) https://github.com/flutter-stripe/flutter_stripe/blob/main/packages/stripe/lib/src/widgets/card_field.dart#L580

Another workaround is to allow the background color to be set from the flutter side in the views; in CardField it is fixed to a transparent color and cannot be set.

oboenikui avatar Jun 29 '22 04:06 oboenikui

Thanks @oboenikui for the research.

According to the docs it makes sense to use the expensive version:

When this factory is used, the Android view and Flutter widgets are composed at the
Android view hierarchy level.
This is only useful if the view is a Android SurfaceView. However, using this method
has a performance cost on devices that run below 10, or underpowered devices.
In most situations, you should use [initAndroidView].

However this forces us to abandon Flutter version 2 and has more known issues: https://github.com/flutter/flutter/issues/107313 . I will keep an eye on it. btw for people that want to try it out: use branch poc-use-expensive-androidview

remonh87 avatar Jul 11 '22 18:07 remonh87

I am also having this issue on the latest version of the plugin (5.0.0). This really makes the Android implementation unusable without applying the "expensive-androidview" fix. Please consider merging that fix into main. Thank you!

ethancadoo avatar Sep 06 '22 22:09 ethancadoo

@ethancadoo can you confirm that the poc-use-expensive-androidview branch works for you?

remonh87 avatar Sep 12 '22 20:09 remonh87

@ethancadoo can you confirm that the poc-use-expensive-androidview branch works for you?

Yes I can.

ethancadoo avatar Sep 12 '22 22:09 ethancadoo

The new version of the package makes uses of the newer initExpensiveAndroidView api. If the issue persists feel free to comment here or open a new issue and we will take a look into it

jamesblasco avatar Dec 10 '22 15:12 jamesblasco