0
votes

I am trying to get the flutter web app to append query param to the end of the url (when a selection is made in UI) without reloading the page

Basically I would like to update the URL from http://127.0.0.1:8080/#/sites to http://127.0.0.1:8080/#/sites?arg=1 without page reload

The following line (import 'dart:html') does not work in flutter (The URL does not change at all)

 window.history.pushState(null, null, '?arg1=1');

I have also tried the js package (https://pub.dev/packages/js) and it does not work either.

Is there a way to get this to work in flutter web or are there any alternatives to achieve my requirement?

1

1 Answers

1
votes

With a bit of struggle, and tried wrapping the call inside a Future.delayed seems to fix that issue.

Future.delayed(
Duration(milliseconds: 100), () => window.history.replaceState(null, null, '${Uri.base.toString()}?accountId=${selectedAccount.accountId}'));

If you have a better answer I would love to know. Thanks