问题描述
我正在尝试在 Google pixel API 30 Emulator 上打开一个链接,但一直出现错误。已尝试Flutter clean,重新启动应用程序。
依赖:-
url_launcher: ^6.0.3
代码:-
InkWell(
onTap:() => _launchURL("https://google.com"),child: Image.asset("assets/images/googleIcon.jpg")
),_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
错误:-
Unhandled Exception: Could not launch https://google.com
解决方法
添加 URI 类,因为 url_launcher 建议将 URL 编码为 URI。 Link to Doc
final Uri _faireGitHubUri = Uri.https('google.com','/');
InkWell(
onTap:() => _launchURL(_websiteUri.toString()),child: Image.asset("assets/images/googleIcon.jpg")
),