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

Time:09-24

  • I am trying to implement Searchbar for my application which will search according to user's firstName.
  • I am facing the below error saying
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

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

CodePudding user response:

Use

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