首页 > 解决方案 > Flutter Firebase 分配编号

问题描述

我正在使用带有颤振的firebase。当我尝试上传产品时出现错误:

type 'double' is not a subtype of type 'int'

当我在 CloudFirestore 中手动输入 cost 时可以解决问题,但我无法从我的应用中添加产品。

这是我的产品模型的数字部分:

   dynamic newPrice, buyPrice;
      dynamic get getNewPrice=> int.parse(newPrice);
    
      set setNewPrice(dynamic newPrice) =>
          this.newPrice= int.parse(newPrice);
 dynamic get getbuyPrice=> int.parse(buyPrice);

  set setBuyoutPrice(dynamic buyPrice) =>
      this.buyoutPrice = int.parse(buyPrice);

错误

在此处输入图像描述

标签: firebasefluttergoogle-cloud-firestore

解决方案


即使您只发送一个 int,Firebase 也会以双精度格式存储数字,因此如果您从 firebase 获取数字类型的数据,您需要将其解析为双精度。如果您在 Firebase 控制台中手动输入整数,您将能够像 int 一样解析它,但这只是“手动破解”。


推荐阅读