在StreamBuilder上,在空Flutter问题上调用了getter'documents'

时间:2020-08-05 11:01:02

标签: flutter google-cloud-firestore

即使应用程序加载并正常工作,我也会收到此类错误:

The getter 'documents' was called on null.
Receiver: null
Tried calling: documents

这是代码:

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: Firestore.instance.collection('shippingAddress').snapshots(),
      builder: (context, snapshot) {
        if(snapshot.data == null) return CircularProgressIndicator();
        if (!snapshot.hasData) return Text('Loading data please Wait');
        return Column(
          children: <Widget>[
            Container(
              height: 1000,
              child: ListView.builder(
                shrinkWrap: true,
                itemCount: snapshot.data.documents.length,
                itemBuilder: (BuildContext context, int index) {
                  return Card(
                    color: Color(0xFF1f2032),
                    child: Container(
                      width: 60,
                      height: 60,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: <Widget>[
                          Text(
                            snapshot.data.documents[index]['alias'],

1 个答案:

答案 0 :(得分:0)

尝试进行如下所示的更改,还请确保与Firebase相比,在您的情况下,“ shippingAddress”节点的拼写是正确的。

true

我尚未测试代码,但应该可以工作