Get the previous route name in Flutter

Viewed 3124

I understand that Flutter routes works like a stack, so I want to know the previous route name which I came from.

I'm using a preview page to show a picture, but this picture can come from the camera or the gallery, I'd like to show a dialog only if it came from gallery.

I read I have to use an observer, but I think there is an easy way to do that.

Thanks in advance.

2 Answers

Well, upon further investigation, there is no way to know the previous page.

I fixed this sending an argument previousPage with the route name value.

You can also use a NavigatorObserver.

You can use getx pack to get previous Route

Get.previousRoute;

get current Route

Get.currentRoute;
Related