-1

I would like when I go to a screen to be able to return to the previous one.

I've tried passing a result when I open the new screen, and then using it as context.go('value');

Example:

context.goNamed('monkey') ;

Back preview page:

context.pop('dog?cat?fox?');

wazoste
  • 1
  • 1
  • 1
    Does this answer your question? [Flutter go\_router how to return result to previous page?](https://stackoverflow.com/questions/71359432/flutter-go-router-how-to-return-result-to-previous-page) – Vega Aug 18 '23 at 11:07

1 Answers1

0
/// The home screen
class HomeScreen extends StatelessWidget {
  /// Constructs a [HomeScreen]
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home Screen')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => context.go('/details'),
          child: const Text('Go to the Details screen'),
        ),
      ),
    );
  }
}

/// The details screen
class DetailsScreen extends StatelessWidget {
  /// Constructs a [DetailsScreen]
  const DetailsScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Details Screen')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => context.go('/'),
          child: const Text('Go back to the Home screen'),
        ),
      ),
    );
  }
}

You can similarly use it for switching between pages, coming back and moving data. You can also check out the documentation: https://pub.dev/packages/go_router/example

You can also benefit from an opened topic link: Flutter go_router how to return result to previous page?

I hope your problem is solved. Enjoy your work.

MobileDev
  • 214
  • 7
  • Thanks, but I think is not work. I have seen the valid comment of the post that you have commented on, but I do not understand how I can use it. – wazoste Aug 18 '23 at 11:35