Search code examples
androidiosflutterwebview

Flutter - launchUrl: When I execute flutter launchUrl(url), the URL I intend to navigate to and the URL that actually opens in the web are different


When calling a URL with launchUrl, the first one or two times it navigates to the correct URL, but after that, it gets stuck on a specific URL. Below is the code I used.

 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";
    }
  }

Why does this happen, and please provide a solution.

I checked if there was an issue with parsing the URL in getReportUrl(), but everything was fine. Also, I logged the URL during the call, and the log showed the correct URL I intended to navigate to.


Solution

  • Upon checking, I found that there was no issue with the Flutter application; the problem was with the cache policy of the website I was trying to access.