Nicolas Lucero
Nicolas Lucero

Reputation: 415

Get the previous route name in Flutter

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.

Upvotes: 8

Views: 11693

Answers (2)

Vu Thanh
Vu Thanh

Reputation: 398

You can use getx pack to get previous Route

Get.previousRoute;

get current Route

Get.currentRoute;

Upvotes: 1

Nicolas Lucero
Nicolas Lucero

Reputation: 415

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.

Upvotes: 4

Related Questions