Lav Sharma
Lav Sharma

Reputation: 339

Error at snapshotData.docs[index].data()['firstName'] flutter

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 ('!').

enter image description here

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

Upvotes: 1

Views: 233

Answers (1)

Huthaifa Muayyad
Huthaifa Muayyad

Reputation: 12353

Use

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

Upvotes: 2

Related Questions