首页 > 解决方案 > snapshotData.docs[index].data()['firstName'] 出现错误

问题描述

The method '[]' can't be unconditionally invoked because the receiver can be 'null'.
Try making the call conditional (using '?.') or adding a null check to the target ('!').

在此处输入图像描述

late QuerySnapshot snapshotData;
..
..
title: Text(snapshotData.docs[index].data()['firstName'], style: TextStyle(
            color: Colors.white,
            fontWeight: FontWeight.bold,
            fontSize: 24.0
          ),
          ),

标签: fluttergoogle-cloud-firestore

解决方案


利用

Text(snapshotData.docs[index].get('firstName'))

推荐阅读