【发布时间】:2022-01-19 05:23:40
【问题描述】:
我收到了来自 API 的响应
{"id":1,"title":"Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops","price":109.95,"description":"Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday","category":"men's clothing","image":"https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg","rating":{"rate":3.9,"count":120}},
我将 price 显示到 Text 小部件中,但它给了我这个错误
type 'double' is not a subtype of type 'int'
请告诉我如何在文本小部件中显示双值
ProductModel 类:
class ProductModel {
ProductModel(
{required this.title,
required this.id,
required this.urlImage,
required this.price});
String title;
int id;
String urlImage;
String price;
factory ProductModel.fromJson(Map<String, dynamic> json) => ProductModel(
id: json["id"],
title: json["price"],
urlImage: json["image"],
price: json["price"]);
Map<String, dynamic> toJson() =>
{"id": id, "title": title, "image": urlImage, "price": price};
}
【问题讨论】:
标签: flutter text integer double