Flutter navigation to same page

Viewed 39

how can I achieve a functionality in my flutter application where I have a product details page and inside this page I have another product listing where similar products. So when I tap on that product tile I want to push same page with different product details? And I use Getx in my project..

example :

HomePage->ProductDetails->ProductDetails

1 Answers

You can do this using the arguments in GetX Route Management. Don't forget to configure the routes to work correctly.

Calling a route

ElevatedButton(
  onPressed: () => Get.to(const PageOne(), arguments: {
  'id': Random().nextInt(1000).toString()
  }), // Passing data by using "arguments"
  child: const Text('Go to page One'),
),

And on the page that will receive the parameters

// Page One
class PageOne extends StatelessWidget {
  const PageOne({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Page One'),
      ),
      body: Center(
        child: Text(
          Get.arguments['id'] ?? 'Page One',
          style: const TextStyle(fontSize: 40),
        ),
      ),
    );
  }
}
Related