flutter_stripe
flutter_stripe copied to clipboard
CardField is constantly redrawing causing animation lag
Describe the bug I integrated Stripe into my app and use the Webhook payment method. Once I got clientSecret from the backend I call Stripe.instance.confirmPayment and display simple animation but the animation lags because CardField constantly redraws wasting processor time (my understanding is that both Android native view renders in the main thread and Flutter also use the same thread what actually cause lags). I looked through the Android code and found that the requestLayout method is called infinitely times (possibly Android Framework calls it). From the Android documentation "If either [requestLayout()](requestLayout or invalidate) were called, the framework will take care of measuring, laying out, and drawing the tree as appropriate" [https://developer.android.com/reference/android/view/View#event-handling-and-threading](Android doc).
I added simple logging to prove it:
` var i = 0
override fun requestLayout() { Log.d(this.javaClass.canonicalName, "requestLayout ${i++}") super.requestLayout() post(mLayoutRunnable) }`
And here is what I got
https://user-images.githubusercontent.com/31043679/209629865-2ecad273-a032-4f86-84f4-34eb67ace78f.mp4
Could you fix the issue because it impacts flutter animation, please?
To Reproduce
- Add logging into the CardFieldView.kt file (requestLayout method)
- Open the Webhook payment screen in the example app
- Observe how many times CardFieldView redraws
Expected behavior CardFieldView should be redrawn only if needed
Smartphone / tablet
- Device: ZTE blade a51, Huawei P Smart plus
- OS: [Android 11, Android 9]
- Package version: [7.0.0]
- Flutter version [3.3.10]