Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

getting an error on transaction function on flutter platform

I am writing a transaction function to add coins in database but I am getting error. The code where error is coming is highlighted in image

The error is : The argument type ‘Set’ can’t be assigned to the parameter type ‘Map<String, dynamic>’

// function to add coin v.i.a transaction method
Future<bool> addCoin(String id, String amount) async {
  try {
    String uid = FirebaseAuth.instance.currentUser!.uid;
    var value = double.parse(amount);
    // these documents are downloaded when you create a stream
    DocumentReference documentReference = FirebaseFirestore.instance
        .collection("users")
        .doc(uid)
        .collection("coins")
        .doc(id);
    FirebaseFirestore.instance.runTransaction((transaction) async {
      DocumentSnapshot snapshot = await transaction.get(documentReference);
      if (!snapshot.exists) {
        documentReference.set({'Amount': value});
        return true;
      }
      double newAmount = snapshot['Amount'].data() + value;
      transaction.update(documentReference,{'Amount' = newAmount  });
      return true;
      
    });

    return true;
  } catch (e) {
    return false;
  }
}

The line where error is coming is highlighted

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

just replace = with : to change the argument from Set to Map:

transaction.update(documentReference,{'Amount' : newAmount  });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading