flutter_stripe icon indicating copy to clipboard operation
flutter_stripe copied to clipboard

Back Button Navigation Issue with Stripe Payment Gateway in Flutter

Open SeemanthWebcastle opened this issue 1 year ago • 7 comments

I am a Flutter developer integrating Stripe payment gateway into my Flutter application. Following the documentation, I switched from using FlutterActivity to FlutterFragmentActivity in MainActivity.kt. After making this change, the back button functionality in my app stopped working as expected.

Steps to Reproduce:

  1. Modify MainActivity.kt to extend FlutterFragmentActivity instead of FlutterActivity.
  2. Build and run the Flutter app.
  3. Navigate to a screen where Stripe payment is implemented.
  4. Attempt to navigate back using the device's hardware back button.

Expected Behavior: When pressing the back button, the app should navigate back to the previous screen within the app.

Actual Behavior: After switching to FlutterFragmentActivity, pressing the back button navigates the app to the home screen of the device instead of navigating back within the app.

Additional Information:

  • Flutter version: 3.19.0
  • Stripe SDK version: ^10.1.1

Possible Cause: The change to FlutterFragmentActivity may have affected the handling of back button events within the Flutter application, possibly due to differences in how FlutterFragmentActivity manages the Flutter view compared to FlutterActivity.

Thank you for your attention to this matter. Please let me know if you require further clarification or additional information to investigate and address this issue effectively.

SeemanthWebcastle avatar Jun 26 '24 09:06 SeemanthWebcastle

"where Stripe payment is implemented" can you clarify what you mean by that? Payment Sheet? CardField?

jonasbark avatar Jun 28 '24 11:06 jonasbark

"where Stripe payment is implemented" can you clarify what you mean by that? Payment Sheet? CardField?

Back button closes app when using app instead of going to previous page.

Vikkybliz avatar Jun 28 '24 17:06 Vikkybliz

Can you provide a reproducible example here? because in my app the backbutton behavior works as expected. Same goes for the example app

remonh87 avatar Jul 01 '24 07:07 remonh87

I am a Flutter developer integrating Stripe payment gateway into my Flutter application. Following the documentation, I switched from using FlutterActivity to FlutterFragmentActivity in MainActivity.kt. After making this change, the back button functionality in my app stopped working as expected.

Steps to Reproduce:

  1. Modify MainActivity.kt to extend FlutterFragmentActivity instead of FlutterActivity.
  2. Build and run the Flutter app.
  3. Navigate to a screen where Stripe payment is implemented.
  4. Attempt to navigate back using the device's hardware back button.

Expected Behavior: When pressing the back button, the app should navigate back to the previous screen within the app.

Actual Behavior: After switching to FlutterFragmentActivity, pressing the back button navigates the app to the home screen of the device instead of navigating back within the app.

Additional Information:

  • Flutter version: 3.19.0
  • Stripe SDK version: ^10.1.1

Possible Cause: The change to FlutterFragmentActivity may have affected the handling of back button events within the Flutter application, possibly due to differences in how FlutterFragmentActivity manages the Flutter view compared to FlutterActivity.

Thank you for your attention to this matter. Please let me know if you require further clarification or additional information to investigate and address this issue effectively.

I am facing the similar issue. Back button is closing the app after integrating stripe

shashikantdwivedi avatar Jul 03 '24 04:07 shashikantdwivedi

I tried solving the issues. This issue is related to issue/related to predictive back not being supported. Here's a github issues which sums up the issue.

https://github.com/flutter/flutter/issues/141564#issuecomment-1893193758

Also to resolve it. Here is a sample AndroidManifest.xml file -

<activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:enableOnBackInvokedCallback="false"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>


        </activity>
    Here, After adding this - android:enableOnBackInvokedCallback="false" in Activity solves the issues for me.

shashikantdwivedi avatar Jul 04 '24 13:07 shashikantdwivedi

But it's not woking

On Thu, Jul 4, 2024 at 7:29 PM Shashikant Dwivedi @.***> wrote:

I tried solving the issues. This issue is related to issue/related to predictive back not being supported. Here's a github issues which sums up the issue.

flutter/flutter#141564 (comment) https://github.com/flutter/flutter/issues/141564#issuecomment-1893193758

Also to resolve it. Here is a sample AndroidManifest.xml file -

<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" @./LaunchTheme" android:enableOnBackInvokedCallback="false" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <meta-data android:name="io.flutter.embedding.android.NormalTheme" @./NormalTheme" />

    </activity>

Here, After adding this - android:enableOnBackInvokedCallback="false" in Activity solves the issues for me.

— Reply to this email directly, view it on GitHub https://github.com/flutter-stripe/flutter_stripe/issues/1822#issuecomment-2209067634, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJOW4VBG4M2QZMMJLAXINV3ZKVIK7AVCNFSM6AAAAABJ5QGTV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBZGA3DONRTGQ . You are receiving this because you authored the thread.Message ID: @.***>

--

Seemanth Sindhukuttan : Flutter Developer *Office: *+91 484 4052626 | www.webcastle.in

SeemanthWebcastle avatar Jul 05 '24 04:07 SeemanthWebcastle

Can you please share more details. Like -

  1. Flutter version
  2. Kotlin version

Also can you make sure that you have done implementation as per the documentation. Also try after adding progaurd rules. Also in app/build.gradle , add this -

buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run
--release` works.
            signingConfig signingConfigs.debug


            proguardFiles getDefaultProguardFile("proguard-android.txt"), "
proguard-rules.pro"
        }
    }

On Fri, Jul 5, 2024 at 9:52 AM SeemanthWebcastle @.***> wrote:

But it's not woking

On Thu, Jul 4, 2024 at 7:29 PM Shashikant Dwivedi @.***> wrote:

I tried solving the issues. This issue is related to issue/related to predictive back not being supported. Here's a github issues which sums up the issue.

flutter/flutter#141564 (comment) < https://github.com/flutter/flutter/issues/141564#issuecomment-1893193758>

Also to resolve it. Here is a sample AndroidManifest.xml file -

<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" @.***/LaunchTheme" android:enableOnBackInvokedCallback="false"

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">

shashikantdwivedi avatar Jul 05 '24 04:07 shashikantdwivedi

This is not something we can change in our library. Stripe requires us to use the FlutterFragmentActivity so I would recommend if you experience problems with the backbutton to raise a ticket there.

remonh87 avatar Jul 10 '24 07:07 remonh87