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

>Solution :

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

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

Leave a Reply