Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page url not changing in flutter, but the page content changes fine

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?

like image 701
Saurabh Khirwal Avatar asked Dec 03 '22 09:12

Saurabh Khirwal


2 Answers

Just add settings: settings, to MaterialPageRoute

like image 104
aoisensi Avatar answered Dec 20 '22 04:12

aoisensi


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.

like image 30
Anirban Das Avatar answered Dec 20 '22 02:12

Anirban Das