'Flutter : read data from firebase using Getx
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'];
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Edgar Manuel Pérez Cob |
