Flutter实时数据库:.childOrderBy()未定义

时间:2019-12-24 11:39:49

标签: firebase flutter firebase-realtime-database dart

我正在努力地查询和查询实时数据库。

 StreamSubscription<Event> _messagesSubscription;
      DatabaseReference _messagesRef =
          FirebaseDatabase.instance.reference().child('messages');

      realTimeDataBaseListen() {
        _messagesSubscription = _messagesRef
            .childOrderBy("Group_id")
            .equalTo("abc123")
            .onChildChanged
            .listen((Event event) {
          print('Child CHANGED: ${event.snapshot.value}');
        }, onError: (Object o) {
          final DatabaseError error = o;
          print('Error: ${error.code} ${error.message}');
        });
      }

但是我得到了错误:

childOrderBy() not defined

我在做什么错了?

谢谢!

1 个答案:

答案 0 :(得分:1)

您应该使用orderByChild

.orderByChild("Group_id")
            .equalTo("abc123")
            .onChildChanged
            .listen((Event event) {

检查以下内容:

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_database/lib/src/query.dart#L165