firebase - 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);
错误
解决方案
即使您只发送一个 int,Firebase 也会以双精度格式存储数字,因此如果您从 firebase 获取数字类型的数据,您需要将其解析为双精度。如果您在 Firebase 控制台中手动输入整数,您将能够像 int 一样解析它,但这只是“手动破解”。
推荐阅读
- python - 如何在 Python 中使用多处理终止进程?
- javascript - 访问 JSON 对象的键值
- python - 使用 Aubio 或 PyAudio 进行音高/音符检测
- java - 如果找到特定字符串,则删除一行
- javascript - 清除普罗米修斯中的指标
- java - Swagger UI 不显示来自自定义注释界面的响应模型
- python - 如何在 python 数据框中将 Object 转换为仅 int 数字?
- android - getGeoPoint() 方法在调用时返回 null。Firebase 集合中有超过 1 个文档
- javascript - 当有人加入服务器时,试图让 Discord 机器人写一条消息
- ios - 需要帮助制作 Swift Cookie Clicker 游戏自动保存