Categories
Mastering Development

Why can’t I access the firestore values in flutter?

Using the example here.

I modified some code to output the the message onTap as follows:

The List is generated with real values from firestore.
but the output is blank. It’s not empty, as I tested with another set of output.
How can I retrieve these real values to use in onTap event handler?

....
return ListView.builder(
  itemCount: messageCount,
  itemBuilder: (_, int index) {
    final DocumentSnapshot document = snapshot.data.documents[index];
    final dynamic message = document['message'];
    return ListTile(
      title: Text(
         message != null ? message.toString() : '<No message retrieved>',
      ),
      subtitle: Text('Message ${index + 1} of $messageCount'),
      onTap: (){
        print(message.toString());

        // OUTPUT: (Nothing)
      },
    );
  },
);
....
onTap: (){
  print(message.toString().isEmpty ? 'Empty' : 'Not Empty');
  //OUTPUT: Not Empty 

  print(message== null ? 'Null' : 'Not Null');
  //OUTPUT: Not Empty 

},

Leave a Reply

Your email address will not be published. Required fields are marked *