Cannot check containsKey on DocumentSnapshot

Viewed 295

I'm trying to check if a field exists in my documentSnapshot.

My code:

document.data.containsKey('field_name')

But I'm getting:

error: The method 'containsKey' isn't defined for the type 'Function'.

Any suggestions?

2 Answers

Try it like this:

(document.data() as Map<String,dynamic>).containsKey('field_name');

Try accessing the data as a function, like this .data()

Related