如何在firestore颤振中放置持续时间?



我正在为电子商务应用程序开发一个学校项目。

我需要保存&;duration &;;在我的应用程序中准备食物并从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
)

您可以使用intl包格式日期时间请。

例如:

var timeHourMinute = DateFormat('H:m').format(DateTime.now()); // 12:30
var timeMinute = DateFormat('m').format(DateTime.now()); // 30

最新更新