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

Flutter接口调用出现Internal Server Error(500):UUID格式错误求助

问题:Flutter调用考勤接口返回500错误,参数格式不符

在Flutter中调用考勤详情接口时遇到**Internal Server Error(500)**错误。Postman测试接口正常,但Flutter里点击「Absensi」按钮跳转至DetailAbsensi页面时,传递的参数是"card $index"格式的字符串。服务器日志显示SQL语句中id_kelas_kuliah的值为"card 0",不符合UUID格式,引发SQL语法错误。

解决方案

核心问题是传递了错误的参数值给接口。接口需要的是课程班级的UUID(id_kelas_kuliah),但当前传的是自定义拼接的"card $index"字符串,导致服务器无法解析为合法UUID,触发SQL错误。

修复步骤

  • 从列表项的数据源中提取真实的id_kelas_kuliah(或对应UUID字段),而非用列表索引拼接字符串
  • 修改跳转逻辑,传递正确的UUID参数
  • 验证参数格式,确保符合服务器要求的UUID规范

修改后的列表页核心代码(仅跳转部分)

// ... 其他代码保持不变
SizedBox(
  width: double.infinity,
  height: 38,
  child: TextButton(
    onPressed: () {
      // 从当前列表项的数据源中获取正确的课程班级UUID
      // 注意:根据你的Datum模型实际字段名调整,比如idKelasKuliah或id_kelas_kuliah
      String kelasId = post.idKelasKuliah.toString();
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => DetailAbsensi(id: kelasId),
        ),
      );
    },
    style: TextButton.styleFrom(
      backgroundColor: const Color(0xffC9F7F5),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(8),
      ),
    ),
    child: Text(
      "Absensi",
      style: bold5.copyWith(
        color: const Color(0xff1BC5BD),
      ),
    ),
  ),
),

补充说明

  • 如果你的列表数据源是data[index]而非post,则替换为data[index].idKelasKuliah.toString()
  • 修改后可在DetailAbsensi的getDetailAbs方法中打印id值,确认传递的是合法UUID格式
  • 确保Datum模型中包含对应课程班级UUID的字段,若没有需先完善接口返回数据的模型解析

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 12:43:18