FutureBuilder小部件仅通过Firebase RealtimeDatabase返回“ DataSnapshot”的实例

时间:2019-08-04 18:36:28

标签: firebase flutter

我无法将FutureBuilder和StreamBuilder小部件与Firebase RealTimeDatabase一起使用,每次尝试以调试打印返回时,我都尝试了很多次来检索RealTimeDatabase中的数据

  

ConnectionState.done值是“ DataSnapshot”的实例,

      FutureBuilder(
      initialData: 1,
      future: FirebaseDatabase.instance.reference().child('hello').once(),
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        print(snapshot);
        return Text(snapshot.data.toString());
      },
    ),

1 个答案:

答案 0 :(得分:1)

您获取数据快照的实例,因此只需添加.value

 FutureBuilder(
  initialData: 1,
  future: FirebaseDatabase.instance.reference().child('hello').once(),
  builder: (BuildContext context, AsyncSnapshot snapshot) {
    print(snapshot);
    return Text(snapshot.data.value.toString());//just add value here
  },
),