Flutter Firebase数据库信息无法保存?

时间:2018-01-01 23:29:33

标签: firebase firebase-realtime-database state flutter

我创建了我的应用的用户Follows / Unfollows部分,我想出了几个问题。最新的协议跟随其他用户并在"下保存一些参考信息"节点。我在我的模拟器中执行此操作时查看了我的Firebase控制台,发现信息显示为绿色,1秒后更改为红色以便删除。这就是我拯救事物的方式......

Future<Null> follow() async {
    await fb
        .child('users/${currentUser}/Follows/${friendsUID}')
        .update({"name": userName, "photo": userImage});
  }

我在构建Widget之前运行以下代码,以确定是否正在关注用户以及应该相应构建哪些按钮....

 void _friends() {
    fb.child("users/${userid}/Follows/${id}").onValue.listen((Event event) {
      setState(() {
        // this will return true or false which is what you want based on your code :)
        friends = event.snapshot.value == null;
      });
    });
  }

我偶尔会收到以下错误消息,但我不确定它是否与保存Firebase有关...

setState() called after dispose(): FriendsVideoPageState#51581(lifecycle state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback. The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

0 个答案:

没有答案