加载网页的webView
WebView(
initialUrl:
'http://test/h5atui//#/mobileMaps?lng=${CommonConfig.lng}&lat=${CommonConfig.lat}',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_webViewController = controller;
},
onProgress: (process){
setState(() {
_processPercent = process / 100;
});
},
onPageFinished: (url) {},
javascriptChannels: <JavascriptChannel>[
_postUpGo(),
_positioningGo(),
].toSet(),
)
1.js传参给移动端文章来源:https://www.toymoban.com/news/detail-563552.html
_postUpGo() {
return JavascriptChannel(
name: 'postUpGo',
onMessageReceived: (JavascriptMessage message) {
dynamic value = json.decode(message.message);
print('value= $value');
var itemType = value['itemType'];
var itemId = value['itemId'];
var type = value['type'];
var wantType = value['wantType'];
///根据获取的参数做跳转之类的相应操作
});
}
2.移动端传参数给web文章来源地址https://www.toymoban.com/news/detail-563552.html
_positioningGo() {
return JavascriptChannel(
name: 'positioningGo',
onMessageReceived: (JavascriptMessage message) async {
var latLng = await LocationUtil().refreshAddressFromLatLng();
if(_webViewController!=null && latLng!=null){
//移动端调用js函数handleCheckChangeEnd并传参
_webViewController.runJavascript('handleCheckChangeEnd("$latLng")');
}
});
}
到了这里,关于flutter js交互传参的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!