当前位置: 首页 > news >正文

Flutter开发type ‘Future<int>‘ is not a subtype of type ‘int‘ in type cast错误

在这里插入图片描述

文章目录

  • 问题描述
    • 错误源码
  • 问题分析
  • 解决方法
  • 修改后的代码

问题描述

今天有个同事调试flutter程序时报错,问我怎么解决,程序运行时报如下错误:
type ‘Future’ is not a subtype of type ‘int’ in type cast

image.png

错误源码

                            int order = DatabaseHelper.dbhelper.getTaskGroupRelationOrder() as int;TaskGroupRelation relation = TaskGroupRelation(id:0,taskId:snapshot.data?[index].id,groupId:widget.groupId,taskOrder:order,);DatabaseHelper.dbhelper.insertTaskGroupRelationData(relation);if (context.mounted) Navigator.of(context).pop();

问题分析

类型“Future<int>”不是类型强制转换中类型“int”的子类型。这里不能强制转换,要拿到DatabaseHelper.dbhelper.getTaskGroupRelationOrde()返回结果可以使用DatabaseHelper.dbhelper.getTaskGroupRelationOrder().then((value) =>{})

解决方法

使用DatabaseHelper.dbhelper.getTaskGroupRelationOrder().then((value) =>{})

修改后的代码

                            TaskGroupRelation relation;DatabaseHelper.dbhelper.getTaskGroupRelationOrder().then((value) =>{relation = TaskGroupRelation(id:0,taskId:snapshot.data?[index].id,groupId:widget.groupId,taskOrder:value,),DatabaseHelper.dbhelper.insertTaskGroupRelationData(relation),if (context.mounted) Navigator.of(context).pop(),});

结束语
Flutter是一个由Google开发的开源UI工具包,它可以让您在不同平台上创建高质量、美观的应用程序,而无需编写大量平台特定的代码。我将学习和深入研究Flutter的方方面面。从基础知识到高级技巧,从UI设计到性能优化,欢饮关注一起讨论学习,共同进入Flutter的精彩世界!
http://www.lryc.cn/news/253371.html

相关文章:

  • Nginx(十二) gzip gzip_static sendfile directio aio 组合使用测试(2)
  • hls实现播放m3u8视频将视频流进行切片 HLS.js简介
  • Ubuntu20.04部署TVM流程及编译优化模型示例
  • 华为OD机试真题-两个字符串间的最短路径问题-2023年OD统一考试(C卷)
  • python try-except
  • flutter开发实战-ValueListenableBuilder实现局部刷新功能
  • 通过时间交织技术扩展ADC采样速率的简要原理
  • FluxMQ—2.0.8版本更新内容
  • 计算机寄存器是如何实现的
  • 两数之和 三数之和 哈希方法
  • Object Detection in 20 Years: A Survey(2019.5)
  • Springboot 设置时区与日期格式
  • 从零开始学Go web——第一天
  • 6.Eclipse里下载Subclipse插件
  • 家用洗地机哪个品牌最好最实用?热门洗地机测评
  • 【C语言:自定义类型(结构体、位段、共用体、枚举)】
  • 【1day】华天软件 OAworkFlowService接口SQL注入漏洞学习
  • Oracle(2-11)RMAN Backups
  • 使用docker搭建『Gitea』私有仓库
  • CopyOnWriteArrayList怎么用
  • 旋转设备状态监测与预测性维护:提高设备可靠性的关键
  • 类和对象——(7)this指针
  • 回溯算法题型分类
  • ApplicationRunner 类
  • QT中的 容器(container)-大全
  • Docker配置镜像加速器
  • 飞致云1panel + 雷池WAF
  • 策略梯度简明教程
  • 鸿蒙原生应用/元服务开发-利用picker选择器来多选相册图片
  • java:封装统一的响应体code、data、msg、paging