Flutter: iOS swipe back gesture with data

787

For iOS you can implement the CupertinoPageRoute instead of MaterialPageRoute like this:

import 'dart:io';
import 'package:flutter/cupertino.dart';

if(Platform.isIOS) {
   CupertinoPageRoute route = CupertinoPageRoute(
                           settings: RouteSettings(arguments: YOUR ARGUMENTS),
                           builder: (context) => SecondPage());

} 
await Navigator.push(context, route);

now you have access the Arguments you passed in the settings prop when you swipe back.

I hope this will fix your Issue.

Share:
787
Chris
Author by

Chris

Updated on December 15, 2022

Comments

  • Chris
    Chris over 1 year

    I'm trying to implement a way to send data back to previous route. The Navigator.of(context).pop function allows a parameter that works perfectly when used with a button-onpress. Problem is: On Android, users can also go back via the Android-specific back button, so I tried to catch this with the help of a WillPopScope-widget. Within the onWillPop parameter, I again use Navigator.of(context).pop(data), so now the job is done on Android. New problem is: Now, due to the WillPopScope widget, swipe-back gestures on iOS dont work anymore.

    So, the question is: How can I send data back to previous route, no matter whether user tapped on a button I put there, tapped on Android-specific back-button or used the swipe-back gesture on iOS?

    Hope it got clear :)