小编Jér*_*our的帖子

flutter/firebase 数据库中的简单查询

我尝试使用 Flutter 体验 Firebase Live 数据库。我只想在 firebase 响应的数据快照中获取一个值。

我的火力基地

在此处输入图片说明

我的代码

static Future<User> getUser(String userKey) async {
Completer<User> completer = new Completer<User>();

String accountKey = await Preferences.getAccountKey();

FirebaseDatabase.instance
    .reference()
    .child("accounts")
    .child(accountKey)
    .child("users")
    .childOrderBy("Group_id")
    .equals("54")
    .once()
    .then((DataSnapshot snapshot) {
  var user = new User.fromSnapShot(snapshot.key, snapshot.value);
  completer.complete(user);
});

return completer.future;
  }
}

class User {
  final String key;
  String firstName;

  Todo.fromJson(this.key, Map data) {
    firstname= data['Firstname'];
    if (firstname== null) {
      firstname= '';
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我的名字为空值。我想我应该导航到 snapshot.value 的孩子。但是无法使用 foreach 或 Map() 进行管理,...

亲切的问候,杰罗姆

firebase firebase-realtime-database flutter

5
推荐指数
1
解决办法
7761
查看次数