【发布时间】:2020-06-18 20:52:44
【问题描述】:
enter image description here[这是前面的屏幕,它是一个 gridTile 并从 firebase 获取数据
<!-- this is the method which the grid time is using to fetch data from firebase-->
Future<void> fetchAndSetProducts() async {
const url ='MY flutter url';
try {
final response = await http.get(url);
final extractedData = json.decode(response.body) as Map<String, dynamic>;
final List<Product> loadedProducts = [];
extractedData.forEach((prodId, prodData) {
loadedProducts.add(Product(
id: prodId,
title: prodData['title'],
description: prodData['description'],
price: prodData['price'],
isFavorite: prodData['isFavorite'],
imageUrl: prodData['imageUrl'],
));
});
_items = loadedProducts;
notifyListeners();
} catch (error) {
throw (error);
}
}
]2
【问题讨论】:
-
附加显示此详细信息的小部件。
标签: json firebase flutter dart async-await