0

This works perfectly when the user clicks on the back button in the app bar. In Android devices, when the user performs a swipe-to-go-back gesture from the right edge of the screen, not able to return data in this case.

I tried using PopScope but not able to navigate to previous screen with data to be returned.

I'm looking for a way to handle the swipe-to-go-back gesture in Android so that I can still return data when the user swipes to navigate back.

PopScope(
                canPop: true,
                onPopInvoked: (didPop) {}, // deprecated
                onPopInvokedWithResult: (didPop, result) {
                  Navigator.of(context).pop(true);
                },

2 Answers 2

0

Set canPop to false, if it is set to true, the screen pops before calling onpopinvokedWithResulth

Sign up to request clarification or add additional context in comments.

Comments

0

Based on the Android-specific swipe behavior, here's the solution for handling both swipe gestures and back button with data. I've faced similar issues.

Here...

  • canPop: false: It's required to handle custom back logic
  • onPopInvoked: Handles both swipe and system back Matching data in both onPopInvoked and back button.
PopScope(
  canPop: false, // It prevents automatic pop behavior
  onPopInvoked: (didPop) async {
    if (didPop) return;
    
    final data = {
      'key': 'value', 
      'status': 'success'
    };
    
    Navigator.of(context).pop(data);
  },
)

That's all you need to handle swipe-back with data return!

Hope it helps you 👍🏻

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.