我如何从扑扑的集合中获取所有用户文档

时间:2020-10-04 16:47:04

标签: firebase flutter dart google-cloud-firestore

我在firestore中有一个名为flpProduct的集合。我想访问存储在flpProduct集合中的所有文档。我曾与许多Futurebuilder和Streambuilder一起尝试过,但没有一个起作用。

我尝试过

 FutureBuilder<QuerySnapshot> (
        future: flpProductFuture,
        builder: (context, snapshot) {
          if (snapshot.hasError) {
            return Center(
              child: Text('Something went Wrong'),
            );
          }

          if (snapshot.connectionState == ConnectionState.done &&
              snapshot.hasData) {
            snapshot.data.documents.forEach((element) {
              print(element.data['title']);
            });
            return Text('done');
          }

          return Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Spinner(),
              Text(
                'Fetching Data',
                style: TextStyle(color: Colors.black54, fontSize: 18.0),
              )
            ],
          );
        },
      ),

这似乎为我获取了数据,但是现在如何在小部件中显示它。 我已经有一个返回容器的类,以在单独的类中显示信息。我只想将数据传递给班级并显示

1 个答案:

答案 0 :(得分:1)

最好使用StreamBuilder而不是FutureBuilder 因为StreamBuilder负责实时更改

def check_events(spaceship):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:  # event.type
            if event.key == pygame.K_RIGHT:  # event.key
                spaceship.moving_right = True
            elif event.key == pygame.K_LEFT:
                spaceship.moving_left = True
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                spaceship.moving_right = False
            elif event.key == pygame.K_LEFT:
                spaceship.moving_left = False