Reputation: 83
I am trying to display the data on the page But this error appears to me Is there a solution to this?
controller
RxInt pprofit = 0.obs ;
void onInit() async{
super.onInit();
// TODO: implement onInit
CollectionReference fprofits = FirebaseFirestore.instance.collection('admin');
await fprofits.doc('profits').get().then((value) {
pprofit = value.data()['profits'];
}); }
iam trying to get this value only
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.
pprofit = value.data()['profits'];
Upvotes: 0
Views: 1277
Reputation: 51
Maybe this can hel you
CollectionReference fprofits = FirebaseFirestore.instance;
final collection = await fprofits.collection('admin').doc('profits').get();
final data = collection.data();
print(data);
you can transform it in Map
CollectionReference fprofits = FirebaseFirestore.instance;
final collection = await fprofits.collection('admin').doc('profits').get();
Map<String, dynamic> data = collection.data() as Map<String, dynamic>;
print(data);
tell if worked for you
Upvotes: 1