颤振 orderBy("time", "asc") 不起作用

时间:2021-04-12 18:26:28

标签: flutter google-cloud-firestore stream-builder

我正在使用嵌套流和未来获取两组数据,但无法按时间对第二组数据进行排序

两个都试了还是不行..为什么???

Error: Getter not found: 'Direction'.
                               .orderBy("time", Query.Direction.DESCENDING)
                                                      ^^^^^^^^^

Error: Too many positional arguments: 1 allowed, but 2 found.
Try removing the extra positional arguments.
                               .orderBy("time", 'asc')
                                       ^

完整代码如下:

return StreamBuilder(
      stream: A,
      builder: (context, snapshot) {
        return snapshot.hasData
            ? ListView.builder(
                ...
                  return
                         FutureBuilder(
                           future: FirebaseFirestore.instance
                           .collection("some path here")
                           .orderBy("time", Query.Direction.DESCENDING)
                           .get(),,

                           builder: (context, snapshot2) {
                           if (snapshot2.hasData) {
                                   if (snapshot2.data!=null) {
                                   return DisplayTile(
                                     ...
                                   );
                                   }
                           }
                           return CircularProgressIndicator();
                           }
                           );
                })
            : Container();
      },
    );

1 个答案:

答案 0 :(得分:2)

orderBy 有 1 个名为 descendingbool 类型的命名参数来传递 order

来自 docs 的示例:

FirebaseFirestore.instance
  .collection('users')
  .orderBy('age', descending: true) // here
  .get()
  .then(...);