4

I am building a flutter web app which requires a url parameter in the start.

Currently it needs a parameter like http://localhost:49844/?id=105897

But after the app catches the url it disappears (like http://localhost:49844/#/) from the web address bar causing the application to fail on refresh of the site. Is there a way to keep the parameter once in the Url path?

In my code I use code below to get the parameter value from the Url

String appUrl = Uri.base.queryParameters["id"].toString();

Also, I use home: instead of routes as I only have a single page to be displayed.

1 Answers1

1

I think you need to try initialRoute and onGenerateRoute instead of home

This is just sample code, you can check docs for a more precise way. And this answer.

  MaterialApp(
    initialRoute: '/?id=105897',
    onGenerateRoute: (settings) {
      Uri uri = Uri.parse(settings.name);
      int id = int.parse(uri.queryParameters['id']);
      return const Home(id);
    },
  );
MJ Studio
  • 3,947
  • 1
  • 26
  • 37