Get the previous route name in Flutter - 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.

You can use getx pack to get previous Route
Get.previousRoute;
get current Route
Get.currentRoute;

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.

Related

How to see GoRouter navigation stack's top element without poping it?

I am building a flutter app. I have a place in the app where you can make infinite loops with
GoRouter.of(context).push(...);
I mean you can navigate to Screen A and then to B and then to A. There are many screens and many possible loops but I want to protect the user from the most obvious one, the A>B>A>B type.
(I don't care about greater loops like A>B>C>A>B>C and alikes)
To do that, I want to check the navigation stack top element and if the element is the same where we would go with a push, I would do a pop.
Problem is that I can't find anything on Google...
Tried:
Googling it, checking API docs, reading IntelliSense
EDIT:
There is a big set of screens and can't know the previous location solely based on the current one.
Use GoRouter.of(context).location
GoRouter.of(context).location gives you the current location
Example:
Route A has route path /routeA
Route B has route path /routeB
GoRouter.of(context).location will return either /routeA or /routeB
Based on which you can make decision to pop() or push() page

Adding a New Image and it changes all images at front page - Flutter

I am making demo application for experience.
So, the problem is that I am adding list as described in images(Screenshots). But when I add another new list with image so, it automatically changes images at front page in the last and new list both. So, can you guys suggest, how we can get new image in list only once and last list stay the same as we added before.
The code is below.
Thanks in advance.
The problem is you are using the list to add images to the list. As the list is callByReference it will change the value inside the list when the value of the listOfImage is changed.
To fix the issue you can change the addition method to map like
allData.add(Model(listOfImage:List.from(list)));
hope it will work for you if not let me know.

flutter- getx nested routes with tab

I am going to build flutter app with Getx.
I followed nested navigator from
https://github.com/jonataslaw/getx/issues/799#issuecomment-730719165
at this example, only shows 1 step sub routes like "/browse".
I need to make another sub routes like "/browse/tabX" and "/browse/tabY"
when click browse button from BottomNavigationBar, It shows tabs (tabX and tabY) on the top. and tabX is default selected.
for the body, it shows automatically their pages.
Also using Get.Named('/browse/tabY') can access to open their page(select second tab and show their body).
Can you help me?
Oh Now I got the answer!
What I make a mistake is I did not use "sub-name".
for example, at initialRoute,
I used '/home/browser' but it should be '/browser' if it is sub-route.
Because the concept is route to subrouter's root and handle by subrouter.
so "initialRoute from root" route to /home first.
and "initialRoute from subroute" route to /browser again!
I use classed variable instead just string so I did not figure this difference out.

Best practice on how to display a widget which content is depending on an async call?

Basically topic.
I am trying to display an image slider with content that I pull from a db. I'm calling for this data in the initstate method. I have managed to do a couple of workarounds, but none of them seem clean enough. I don't necessarily need to call it from initstate, but I need that it shows up as I open the screen.
Thanks in advance.
If it's an image, you can use a package called blurhash, Google it for more information regarding that.

How do i get touch event on WebView

Hope you all are fine and also in one of your best moods!!
I have one problem in Map based application. kindly go through it and post your suggestion.
Thing at Glance:
I need to integrate map in my application.
application shows map based on passing parameter as state and city.
i am using yahoo map image for that.
i.e.
pass parameter as following:
state : CA
city : Loss Angelous.
it shows image of map perfectly that i load on webview.
now issue is here:
i need to put button at selected city.. i don't know how do i put.
because on clicking button i need to load another view that contains Details of that city.
I don't know how do i do this.
Kindly give your suggestion.
Thank you.
Arun Thakkar.
Using the iPhone SDK 3.0 you can use the MKMapKit framework to embed a map in your application, and you can add custom annotations. Here's the MKMapView documentation.