JonasWanke/swipeable_page_route

Receiving a value back from a pop.

jarzac opened this issue · 1 comments

jarzac commented

I replaced MaterialPageRoute with SwipeablePageRoute, but it looks like I lost the capability of receiving a value back from the pop. This is my push:

Navigator.of(context).push(SwipeablePageRoute(
  builder: (BuildContext context) => DetailView(pieceId: pieceId),
)).then((value) {
  if (value == 'update') {
    setState(() {}); // This will rebuild your Home View
  }
});

This is my pop:

  Navigator.pop(context, 'update');

Is this a feature that could be added? I will take a look at your code and see if I can provide a solution.

Hi, and sorry for the really late response! Popping the SwipeablePageRoute with a value should work as expected, and I can't reproduce this problem. The code below prints “Result: null” when swiping the page away and “Result: update” when clicking the “Pop” button:

import 'package:flutter/material.dart';
import 'package:swipeable_page_route/swipeable_page_route.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '🔙 swipeable_page_route example',
      home: FirstPage(),
    );
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MorphingAppBar(title: const Text('Page 1')),
      body: ElevatedButton(
        onPressed: () async {
          final result = await Navigator.of(context).push<String>(
            SwipeablePageRoute(builder: (_) => SecondPage()),
          );
          print('Result: $result');
        },
        child: const Text('Open page 2'),
      ),
    );
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MorphingAppBar(title: const Text('Page 2')),
      body: ElevatedButton(
        onPressed: () async => Navigator.pop(context, 'update'),
        child: const Text('Pop'),
      ),
    );
  }
}

Please reopen this issue if the problem still occurs and provide the full code to reproduce it