How to enable Location in Flutter with flutter_webview plugin?

Viewed 3382

I am currently using flutter_webview plugin for a project. In one of the page, I need to get the user location information to calculate the distance. There is JavaScript running on the webpage to get the location.

Here is my sample code.

WebView(
  key: _key,
  initialUrl: "https://www.w3schools.com/html/html5_geolocation.asp",
  javascriptMode: JavascriptMode.unrestricted,
  onPageFinished: (_) {
    setState(() {
      _isLoading = false;
    });
  },
),

If I open the same page on chrome, it asks for the location permission. I wanted to implement something like that.

I tried using permissions on AndroidManifest file but could not make it work.

1 Answers

you have to use flutter_webview_plugin, there is a geolocation property you can enable it.
check this code

 Widget build(BuildContext context) { 
return WebviewScaffold( 
  url: url, 
  withZoom: true, 
  hidden: true, 
  geolocationEnabled: true,
);
} 
Related