1
  • 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
          ),
          ),
Lav Sharma
  • 327
  • 1
  • 5
  • 23
  • Check This : https://stackoverflow.com/questions/68254952/flutter-null-safety-the-method-cant-be-unconditionally-invoked-because-th – Yashraj Sep 23 '21 at 05:17

1 Answers1

2

Use

Text(snapshotData.docs[index].get('firstName'))
Huthaifa Muayyad
  • 11,321
  • 3
  • 17
  • 49