Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: passing data to WebView

I get the location in my Flutter app. I have a WebView and I want to pass the location inside it (to handle it after in the site opened within the webview).

var userLocation = Provider.of<UserLocation>(context);

And my WebView:

WebView(
      initialUrl: widget.url,
      javascriptMode: JavascriptMode.unrestricted,
 )

Is there a way to do it? My goal is like a binding between flutter and angular sending continuous location data.

like image 703
Edoardo Tavilla Avatar asked Oct 04 '19 12:10

Edoardo Tavilla


1 Answers

normally To receive data from flutter we add js function in html

function fromFlutter(location) {
    document.getElementById("locationId").innerHTML = location;
    sendBack();
}

and then in flutter create a web view controller then

_controller.evaluateJavascript('fromFlutter("From Flutter")');

or for variable containing location

_controller.evaluateJavascript('fromFlutter("$locationVar")');
like image 159
Sa9 Avatar answered Oct 11 '22 13:10

Sa9