'Flutter Web: How to get query params from service worker?

I have a native website (e.g. blabla.com) and I'm passing data with query parameters to a flutter website. Params not showing in link. But I can see in devtool my data.

enter image description here

enter image description here

My question is; how can I get data from service worker. Thanks...



Solution 1:[1]

I found a solution to use. in web/index.html, I've created a function:

<script type="application/javascript">
  const params = new Proxy(new URLSearchParams(window.location.search), {
    get: (searchParams, prop) => searchParams.get(prop),
   );

  function getEmail() {
    return params.email;
  }
</script>

and in the main.dart file, I imported dart:js package

import 'dart:js' as js;

and I call it that I've created javascript function in web/index.html

String? email;
  
Future<void> getEmail() async {
  setState(() {
    email = js.context.callMethod('getEmail');
  });
}

I added the codes above in case other people need it. thanks

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Serdar Polat