Flutter 中的 StreamBuilder 卡住了 ConnectionState.waiting 并只显示加载标记

Adn*_*ali 8 async-await dart firebase flutter stream-builder

嗨,我正在尝试将 Firebase 文档中的数据动态显示到我的 Flutter 中,并在其中使用循环进行渲染,因此我创建了一个List<Widget> Cards并添加了makeItem()包含卡片的函数,并将它们放入循环中,所以问题是当我运行它输出的代码print(snapshot.connectionState);ConnectionState.waiting所有的时间,它应该是异步快照但它拒绝为需要加载的数据,我应该提到的是,数据显示被通缉时,我打“Android Studio中热负荷”。所以我不知道如何解决这个问题。提前致谢

Can*_*nar 2

你可以尝试以下方法吗?

class MyList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: _firestore.collection(widget.city).snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError)
          return Text('Error: ${snapshot.error}');
        switch (snapshot.connectionState) {
          case ConnectionState.waiting: return Center(child: CircularProgressIndicator(backgroundColor: Colors.amber,strokeWidth: 1),),
          default:
            return ListView(
              children: snapshot.data.documents.map((DocumentSnapshot document) {
                return makeItem(
                  pointName: document['name'],
                  huge: document['lastname'],
                  moderate: document['mobileNumber'],
                  none: document['location'],
                  fights: document['job'],
               );
              }).toList(),
           );
        }
      },
    );
  }
}
Run Code Online (Sandbox Code Playgroud)