【发布时间】:2022-06-11 00:15:44
【问题描述】:
我尝试使用流从 firebase 获取 timestamp 数据并将其显示在数据表中,但时间戳是 (seconds=1560523991, nanoseconds=286000000) 的格式,我如何将其转换为 dd-mm-yyyy 格式。我尝试使用DateFormat() 解析它,但没有成功。
代码
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('lender')
.doc(auth.currentUser!.email)
.collection('paymentData')
.where('name',
isEqualTo: Provider.of<UpdateNameProvider>(context,
listen: false)
.bname)
//.orderBy('paidDate', descending: true)
.snapshots(),
//.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(
backgroundColor: Color(0xff8eacbb),
));
} else if (snapshot.data!.docs.isEmpty) {
return const Center(
child: Text(
'Press + to add data',
style: TextStyle(fontSize: 20),
),
);
} else {
return Center(
child: Container(
child: DataTable(
columns: const [
DataColumn(label: Text('Amount')),
DataColumn(label: Text('Paid Date'))
],
rows: snapshot.data!.docs.map((data) {
// DateTime datee = data['paidDate'];
return DataRow(cells: [
DataCell(Text(data['amount'])),
DataCell(Text(data['paidDate'].toString()))
]);
}).toList()),
));
//print(snapshot.data!.docs);
}
})
【问题讨论】:
标签: flutter firebase google-cloud-firestore flutter-streambuilder