0

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 enter image description here

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'];
2
  • I hope someone can help me Commented Mar 9, 2022 at 22:12
  • Have you double checked that value.data() is actually the value you're expecting? Try printing it out or setting a breakpoint there to check it out Commented Mar 10, 2022 at 1:23

1 Answer 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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.