I have a firebase object that a user increments but can't increment to a certain number. I want to have a condition in the transaction to prevent the user from incrementing past a set number. How do I cancel the transaction and return an error to the user i.e
try {
int setLimit = 12; //example limit... Can vary
final TransactionResult transactionResult = await myRef.runTransaction((MutableData mutableData) async {
var currentValue = mutableData.value ?? 0;
if (currentValue >= setLimit) {
throw 'full'; // .... how do I return from this (return throws error ... Expects MutableData)
}
mutableData.value = (mutableData.value ?? 0) + 1;
return mutableData;
});