【问题标题】:problem with sorting data by time from firestore flutter从firestore颤振按时间排序数据的问题
【发布时间】:2021-01-29 09:30:31
【问题描述】:

我正在尝试使用 orderBy() 在颤振上对一些数据进行排序 当我尝试按名称或任何内容排序但不使用时间时,它会起作用 这就是我在 Fire Store 上存储数据的方式

FirebaseFirestore.instance.collection('cars').add({
      'time ': Timestamp.now(),
      'name': name,
      'phone': mobile,});

这是排序代码

 stream: FirebaseFirestore.instance
                    .collection('cars')
                    .orderBy('time', descending: true)
                    .snapshots(),

即使在 firebase 控制台中,排序也不起作用,但是当我从控制台添加时间戳时 它直接工作,我可以按时间排序,但我从代码中添加的数据没有用它排序。

【问题讨论】:

  • 你用什么插件来生成时间戳?
  • 我是 Flutter 新手,你能解释一下你对时间戳插件的意思吗
  • Timestamp 类是什么?
  • 我用它来为 StatefulWidget 表单中的表单数据添加时间,如果你的意思是这样的话
  • 我发现问题是'时间'有一个空间来尝试帮助

标签: firebase flutter dart google-cloud-firestore timestamp


【解决方案1】:

像这样使用DateTime.now()

FirebaseFirestore.instance.collection('cars').add({
      'time ': DateTime.now(),
      'name': name,
      'phone': mobile,});

希望你能得到答案

【讨论】:

    猜你喜欢
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 2020-12-14
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 2020-05-15
    相关资源
    最近更新 更多