1

from the previous question that I have posted, I already managed to send a push notification to all device. Previously, I am using the different version of plugin which are:

firebase_core: ^1.0.1
cloud_firestore: ^1.0.1
firebase_dynamic_links: ^0.8.0

But, there are some issue on compatibility for my firebase connection as I need to change from

classpath 'com.google.gms:google-services:4.3.5'

to

classpath 'com.google.gms:google-services:4.3.8'

So, due to compatibility issue, i need to change the version of plugin as well to

firebase_core: ^1.2.0
cloud_firestore: ^2.2.0

However, after change the version. Some of my code didn't work. My concern is on how to specify which field that I want to call using snapshot.data(). Previously, I am using snapshot.data()['token'] and it's work fine. But after I change version on firebase_core, I cannot using that method again. It stated error which is:

Error: The operator '[]' isn't defined for the class 'Object'.

  • 'Object' is from 'dart:core'. Try correcting the operator to an existing operator, or defining a '[]' operator. 'to': snapshot.data() ['tokenID'],

Can anyone help me on this issue? Thank you in advanced! You many check the full code here

jat
  • 75
  • 1
  • 7

1 Answers1

0

You can cast snapshot.data() to a Map like shown below:

    (snapshot.data() as Map<String, dynamic>) ['tokenID']

Checkout the migration guide for cloud_firestore 2.0.0.

With the release of withConverter, numerous classes/functions take an extra generic parameter. In most cases, type inference should take care of the migration for you. But in some cases, you may have to specify that generic parameter yourself.

Victor Eronmosele
  • 7,040
  • 2
  • 10
  • 33