'How to resolve The operator '[]' isn't defined for the type 'Object'?
Currently working on Grocery Application but getting an error: The operator '[]' isn't defined for the type 'Object'. Tried searching online but got no solution. Flutter Developers help me resolve the error.
import 'package:cloud_firestore/cloud_firestore.dart';
class UserModel{
static const NUMBER = 'number';
static const ID = 'id';
late String _number;
late String _id;
String get number => _number;
String get id => _id;
UserModel.fromSnapShot(DocumentSnapshot documentSnapshot){
_number = documentSnapshot.data()![NUMBER];
_id = documentSnapshot.data()![ID];
}
}
UPDATE: ERROR FIXED
import 'package:cloud_firestore/cloud_firestore.dart';
class UserModel{
static const NUMBER = 'number';
static const ID = 'id';
String? _number;
String? _id;
String? get number => _number;
String? get id => _id;
UserModel.fromSnapShot(DocumentSnapshot<Map<String,dynamic>> documentSnapshot){
_number = documentSnapshot.data()![NUMBER];
_id = documentSnapshot.data()![ID];
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

