flutter-stripe / flutter_stripe

Flutter SDK for Stripe.
https://pub.dev/packages/flutter_stripe
961 stars 532 forks source link

App crashing in Android with: Fatal Exception: java.lang.IllegalArgumentException: end cannot negative. [end: -1] #1060

Closed noebt closed 1 year ago

noebt commented 1 year ago

Describe the bug I'm using the plugin in my Flutter app and everything has worked correctly until now. A user who used the Stripe payment with Stripe.instance.presentPaymentSheet() did the payment correctly, which I received, but not the following actions. This is the function I call:

try {
            await Stripe.instance.presentPaymentSheet();
            await globals.finalOrder.createOrder(); --> didn't execute and didn't throw error
            await BDPAPI.createOrder(globals.finalOrder); --> didn't execute and didn't throw error
            Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => SuccessPage()));
} catch (e, trace) {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                content: Text("Error"),
            ));
            FirebaseCrashlytics.instance.log("${e}, order: ${globals.finalOrder}");
            FirebaseCrashlytics.instance.recordError(
                e,
                trace
            );
}

It happened with a Redmi 9 (Android 10). I checked Crashlytics and I saw a crash at the time the user reported which happened in the PaymentSheetActivity:

BaseContinuationImpl.java line 11
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith

And the trace:

Fatal Exception: java.lang.IllegalArgumentException: end cannot negative. [end: -1]
       at androidx.compose.ui.text.TextRangeKt.packWithCheck(TextRangeKt.java:56)
       at androidx.compose.ui.text.TextRangeKt.TextRange(TextRangeKt.java)
       at androidx.compose.foundation.text.selection.TextFieldSelectionManager.updateSelection(TextFieldSelectionManager.java:90)
       at androidx.compose.foundation.text.selection.TextFieldSelectionManager.access$updateSelection(TextFieldSelectionManager.java)
       at androidx.compose.foundation.text.selection.TextFieldSelectionManager$touchSelectionObserver$1.onDrag-k-4lQ0M(TextFieldSelectionManager.java:117)
       at androidx.compose.foundation.text.LongPressTextDragObserverKt$detectDragGesturesAfterLongPressWithObserver$5.invoke-Uv8p0NA(LongPressTextDragObserverKt.java:7)
       at androidx.compose.foundation.text.LongPressTextDragObserverKt$detectDragGesturesAfterLongPressWithObserver$5.invoke(LongPressTextDragObserverKt.java:8)
       at androidx.compose.foundation.gestures.DragGestureDetectorKt$detectDragGesturesAfterLongPress$5$1$1.invoke(DragGestureDetectorKt.java:15)
       at androidx.compose.foundation.gestures.DragGestureDetectorKt$detectDragGesturesAfterLongPress$5$1$1.invoke(DragGestureDetectorKt.java:2)
       at androidx.compose.foundation.gestures.DragGestureDetectorKt.drag-jO51t88(DragGestureDetectorKt.java:96)
       at androidx.compose.foundation.gestures.DragGestureDetectorKt$drag$1.invokeSuspend(DragGestureDetectorKt.java:12)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:11)
       at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTaskKt.java:85)
       at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTaskKt.java:51)
       at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.java:7)
       at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.java:29)
       at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.java:7)
       at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.java:10)
       at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter$PointerEventHandlerCoroutine.offerPointerEvent(SuspendingPointerInputFilter.java:27)
       at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter.dispatchPointerEvent(SuspendingPointerInputFilter.java:50)
       at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter.onPointerEvent-H0pRuoY(SuspendingPointerInputFilter.java:18)
       at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(Node.java:108)
       at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(Node.java:90)
       at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(Node.java:90)
       at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(Node.java:90)
       at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(Node.java:90)
       at androidx.compose.ui.input.pointer.NodeParent.dispatchMainEventPass(NodeParent.java:34)
       at androidx.compose.ui.input.pointer.HitPathTracker.dispatchChanges(HitPathTracker.java:29)
       at androidx.compose.ui.input.pointer.PointerInputEventProcessor.process-BIzXfog(PointerInputEventProcessor.java:192)
       at androidx.compose.ui.platform.AndroidComposeView.sendMotionEvent-8iAsVTc(AndroidComposeView.java:57)
       at androidx.compose.ui.platform.AndroidComposeView.handleMotionEvent-8iAsVTc(AndroidComposeView.java:136)
       at androidx.compose.ui.platform.AndroidComposeView.dispatchTouchEvent(AndroidComposeView.java:68)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3141)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2803)
       at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:496)
       at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1853)
       at android.app.Activity.dispatchTouchEvent(Activity.java:4059)
       at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:2)
       at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:454)
       at android.view.View.dispatchPointerEvent(View.java:13774)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5808)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5599)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5096)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5149)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5115)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5255)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5123)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5312)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5096)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5149)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5115)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5123)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5096)
       at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7939)
       at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7908)
       at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7859)
       at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8081)
       at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:250)
       at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(InputEventReceiver.java)
       at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:212)
       at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:8025)
       at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:8105)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:969)
       at android.view.Choreographer.doCallbacks(Choreographer.java:793)
       at android.view.Choreographer.doFrame(Choreographer.java:721)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:954)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:224)
       at android.app.ActivityThread.main(ActivityThread.java:7561)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)

Does anyone know what can be the cause for that?

jamesblasco commented 1 year ago

This seems like a bug in the Jetpack Compose library used by the stripe-android sdk. There is no much we can do in this project than to wait for it to be fixed and to update the dependencies when is solved:

https://issuetracker.google.com/issues/228862731