使用 launchUrl 调用 URL 时,前一两次它会导航到正确的 URL,但此后,它会卡在特定 URL 上。下面是我使用的代码。
String getReportUrl() {
final String formattedDate =
DateFormat('yyyy-MM-dd').format(strToDateTime(errorDate));
print(
"CALL https://www.aaa.net/bbb/ccc-ddd?store=${data.store}&startDate=$formattedDate&endDate=$formattedDate");
return "https://www.aaa.net/bbb/ccc-ddd?store=${data.store}&startDate=$formattedDate&endDate=$formattedDate";
}
void _clickURL() async {
Uri url = Uri.parse(getReportUrl());
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw "Could not launch $url";
}
}
为什么会出现这种情况,请提供解决方案。
我检查了 getReportUrl() 中解析 URL 是否存在问题,但一切正常。另外,我在通话期间记录了 URL,并且日志显示了我想要导航到的正确 URL。
经检查,发现Flutter应用没有问题;问题出在我尝试访问的网站的缓存策略上。