Hi I am trying to implement a page in flutter web that takes an id from the url and shows data according to that id. It's working in the sense that the page gets the data, but the url itself is not changing in the browser.
For the routes section I have put this
onGenerateRoute: (settings) {
List<String> routeSplit = settings.name.split('/');
if (routeSplit[1] == 'pdp' && routeSplit.length > 2) {
int pdpId = int.parse(routeSplit[2]);
return MaterialPageRoute(
builder: (context) =>
ActivityDescriptionPage(id: pdpId));
}
},
From this the page gets the id. And to send to the page from the code I use this:
onTap: () => Navigator.pushNamed(context, '/pdp/' + activityId.toString())
So when i execute the above line from say /products
page, the new page content is loaded but the url in the browser remains /products
only. Am I doing something wrong here?
Just add settings: settings,
to MaterialPageRoute
Pass the settings in MaterialPageRoute. Like this,
onGenerateRoute: (settings) {
List<String> routeSplit = settings.name.split('/');
if (routeSplit[1] == 'pdp' && routeSplit.length > 2) {
int pdpId = int.parse(routeSplit[2]);
return MaterialPageRoute(
settings: settings,
builder: (context) => ActivityDescriptionPage(id: pdpId)
);
}
},
It will change the page content & the URL as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With