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的精彩世界!

相关推荐

  1. Flutter开发指南

    2023-12-05 23:56:03       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-05 23:56:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-05 23:56:03       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-05 23:56:03       87 阅读
  4. Python语言-面向对象

    2023-12-05 23:56:03       96 阅读

热门阅读

  1. 国产Euler(欧拉)系统安装docker

    2023-12-05 23:56:03       54 阅读
  2. QLineEdit 的 InputMask掩码

    2023-12-05 23:56:03       56 阅读
  3. Example: use raspberry pi 4 control multiple motors(tb660)

    2023-12-05 23:56:03       58 阅读
  4. 向量数据库

    2023-12-05 23:56:03       61 阅读
  5. 如何在嵌入式系统中使ECU发出的首帧为NM帧

    2023-12-05 23:56:03       53 阅读
  6. 深入理解服务器进程管理与优化

    2023-12-05 23:56:03       61 阅读
  7. 自制编程语言(第三弹)定义Token

    2023-12-05 23:56:03       59 阅读
  8. ESP网络开发实例-通过WebSocket控制步进电机

    2023-12-05 23:56:03       58 阅读
  9. C# freesql技术 常用的增删改查sql命令

    2023-12-05 23:56:03       57 阅读
  10. 蓝桥杯ACwing习题

    2023-12-05 23:56:03       46 阅读
  11. 修改git仓库地址

    2023-12-05 23:56:03       54 阅读
  12. Ansible 自动化运维企业实战 (三)

    2023-12-05 23:56:03       68 阅读