Flutter web - Window.history.pushState 不起作用

Flutter web - Window.history.pushState does not work

我正在尝试让 flutter web 应用程序将查询参数附加到 url 的末尾(当在 UI 中进行选择时)而不重新加载页面

基本上我想在不重新加载页面的情况下从 http://127.0.0.1:8080/#/sites to http://127.0.0.1:8080/#/sites?arg=1 更新 URL

下面一行(import 'dart:html')在flutter中不起作用(URL根本没有改变)

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

我也试过js包(https://pub.dev/packages/js),也没用

有没有办法让它在 flutter web 中工作,或者有什么替代方法可以满足我的要求?

经过一番努力,尝试将调用包装在 Future.delayed 中似乎可以解决该问题。

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

如果您有更好的答案,我很想知道。谢谢