Home > Back-end >  Flutter 3.3.4 - The operator '[]' isn't defined for the class 'Object'
Flutter 3.3.4 - The operator '[]' isn't defined for the class 'Object'

Time:10-20

I just upgraded to Flutter 3.3.4 and now get this error:

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.
                                            : file.data()!['photo'];

Code looks like this:

Future<String?> getUsersPhoto(String uid) async {

    final reference = FirebaseFirestore.instance.doc('users/$uid');
    DocumentSnapshot doc = await reference.get();
    var result = doc.data()!['photo'];

    return result;
}

enter image description here

And a more complex function like this:

 Stream<T> findUser<T> ({required String uid, required T builder(Map<String, dynamic>? data, String documentID)}) {
    final ref = FirebaseFirestore.instance.doc('users/$uid');
    final Stream<DocumentSnapshot> snapshots = ref.snapshots();

    return snapshots.map((snapshot) => builder(snapshot.data(), snapshot.id));
  }

enter image description here

Any idea how to progress from here?

CodePudding user response:

Convert doc.data() to as Map<String, dynamic>.

Map<String, dynamic> data = doc.data()! as Map<String, dynamic>;
return data['photo']
  • Related