【发布时间】:2021-10-08 12:16:33
【问题描述】:
我正在为 Flutter 中的电子商务应用开发一个学校项目。
我需要在我的应用程序中保存准备食物的“持续时间”并从 Firestore 中检索它。我需要将其保存为时间戳吗?如果是这样,我将如何检索它并将其再次转换为持续时间,以便显示食物准备的分钟或小时?
这是我的代码示例:
class ProductModel {
String? productName;
String? prdouctImgUrl;
double? productPrice;
// Duration? preparationTime; ===> the preparation time of the food
ProductModel();
ProductModel.fromSnapshot(DocumentSnapshot snap){
productName = snap["productName"];
prdouctImgUrl= snap["prdouctImgUrl"];
productPrice= snap["productPrice"];
//preparationTime= snap["preparationTime"];
}
}
//showing of products
.....
_product = ProductModel.fromSnapshot(snapshot.data!.docs[i]);
return ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(_product.prdouctImgUrl),
child: _product.prdouctImgUrl.isEmpty
? Text("${_product.productName[0].toUpperCase()}") : SizedBox(),
radius: 15,),
title: Text(_product.productName),
//subtitle: Text("Preparation time ${_product.preparationTime]} \n Expected delivery date: ${DateTime.now().add(_product.preparationTime])}"),
// ???? I want to show how many minutes the preparation time is and when can the customer receive the items
)
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore