So I’m Using Getx
‘s routing in Flutter.
I have a Product class that accepts an argument of the type Product
const Produkt({
required this.product,
});
I handle the navigation through GetPages, like:
GetPage(
name: Produkt.route,
page: () => Produkt(
product: Get.arguments['product'],
),
),
But of course, this only works when the arguments aren’t null. How could I redirect to an error page when the arguments are null?
2
Answers
you can set a simple condition inside the
build()
method of yourProdukt
widget like this:now based on
product
value, you can implement aYourErrorScreenWidget()
if it’s null, and your specificWidegtOfProdukt()
when it’s not.another solution is that you can make a check in the constructor to navigate to another screen when it’s null, otherwise it will just work fine
Note: you could also call the
Get.off()
to navigate to another screen from thebuild()
method, but I guess there is no point of getting inside thebuild()
method since you’re going to navigate anyway.