You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter报错:Uri类型无法分配给WebUri?参数的解决方法

修复Uri无法赋值给WebUri?的类型错误
  • 问题核心:你使用的inappwebview库中,URLRequest的url参数要求的是该库自定义的WebUri?类型,而非Dart原生的Uri类型,因此出现类型不匹配错误。

  • 修复方案:将Uri.parse(selectedUrl!)替换为WebUri(selectedUrl!)(部分版本也支持WebUri.parse(selectedUrl!)写法,效果一致)。

修改后的完整代码:

await browser?.openUrlRequest(
      urlRequest: URLRequest(url: WebUri(selectedUrl!)),
      options: InAppBrowserClassOptions(
        crossPlatform:
            InAppBrowserOptions(hideUrlBar: true, hideToolbarTop: true),
        inAppWebViewGroupOptions: InAppWebViewGroupOptions(
          crossPlatform: InAppWebViewOptions(
              useShouldOverrideUrlLoading: true, useOnLoadResource: true),
        ),
      ),
    );

说明:inappwebview库封装了自身的URL处理类WebUri,用于适配WebView的跨平台URL处理逻辑,必须使用该类型才能满足URLRequest的参数要求。

内容的提问来源于stack exchange,提问作者Rayan syed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 19:12:02