问题
I am developing WebApp in Flutter but when I click on tel:987654321
or mailto:
links going page Not Found,
To open the default app in mobile I am using url_launcher dependency But in the background when I click WebView also run the same link and go to page not found.
How to handle this task?
回答1:
navigationDelegate: (NavigationRequest request) {
if(request.url.contains("mailto:")) {
launch(request.url);
return NavigationDecision.prevent;
}
else if (request.url.contains("tel:")) {
launch(request.url);
return NavigationDecision.prevent;
}
},
回答2:
Add some details, need url_launcher
plugin
import 'package:webview_flutter/webview_flutter.dart';
import 'package:url_launcher/url_launcher.dart';
_launchURL(url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
in Widget-build ...
WebView(
initialUrl: 'http://example.com',
navigationDelegate: (NavigationRequest request) {
if (request.url.contains("mailto:")) {
_launchURL(request.url);
return NavigationDecision.prevent;
} else if (request.url.contains("tel:")) {
_launchURL(request.url);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
)
来源:https://stackoverflow.com/questions/56421218/how-to-allow-mailto-and-tel-url-schemes-in-webview-flutter