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

Flutter调用Uri.https发起GET请求报错int不是Iterable<dynamic>子类型

报错原因
  1. Uri构造参数类型不匹配
    Dart的Uri.https构造函数的queryParameters入参要求Map的value必须是String类型或Iterable<String>类型,你当前传入的参数{'maxId': 0, 'minId': 0, 'count': 20}中所有值都是int类型,不符合Dart的Uri构造规则,因此在构造Uri阶段就抛出了type 'int' is not a subtype of type 'Iterable<dynamic>'的类型错误。
    Postman测试正常是因为Postman会自动将数字类型的查询参数转为字符串拼接至URL,Dart不会默认做该隐式转换。

  2. 拦截器无日志原因
    异常在Uri构造阶段就已抛出,此时请求还未提交给InterceptedClient处理,因此拦截器逻辑完全没有被触发,自然不会输出拦截日志。

解决方案

你只需要将查询参数的所有值转为String类型即可,有两种常用实现方式:

  • 直接手动转写参数值
Uri.https(
  serverUrl,
  '/$apiKeyword/$path/',
  queryParams == null ? null : {'maxId': '0', 'minId': '0', 'count': '20'},
),
  • 动态参数自动转换(适合参数值是动态生成的场景)
Map<String, dynamic> rawParams = {'maxId': 0, 'minId': 0, 'count': 20};
Map<String, String> processedParams = rawParams.map((key, value) => MapEntry(key, value.toString()));

Uri.https(
  serverUrl,
  '/$apiKeyword/$path/',
  queryParams == null ? null : processedParams,
),

修改完成后Uri即可正常构造,请求会正常进入拦截器流程输出日志。

内容的提问来源于stack exchange,提问作者Cyrus the Great

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 14:27:01