How to use URL parameters in Flutter Web?

Viewed 218

I want to make it so when a user enters the URL of the app they'd get the same page, no matter what they added after the '/', but have a string stored in the code with the value after the '/'.

for example: if they enter the URL "exampleurl.app/blabla", the String would have the value "blabla".

I managed to that somewhat with Uri.base, the problem is that after the app loads the URL removes all the text after the '/' automatically, and whenever I reload the site it reloads it without the URL with the text removed. Also if the current URL in the tab is already of the app ("exampleurl.app/nomatterwhatsaddedhere"), it assumes that it is the same URL and doesn't even reload.

It would be greatly appreciated if someone could show me a way to get the string from the URL without these issues.

Thanks in advance!

1 Answers

You need to use Navigator 2.0 for this kind of functionality. I recently wrote a short series that explains simply how to implement Navigator 2.0. It goes into detail explaining how to work with the URL in an app for similar functionality to what you are after, though you will need to tweak it for your use case. It provides a detailed walkthrough along with sample code available on GitHub.

A Simpler Guide to Flutter Navigator 2.0

Related