calculate method

List<Map<String, dynamic>> calculate(
  1. String field,
  2. num value, {
  3. String operator = '+',
})

Implementation

List<Map<String, dynamic>> calculate(String field, num value,
    {String operator = '+'}) {
  final operatorMap = {'+': (a, b) => a + b, '-': (a, b) => a - b};
  final calculatedDocuments = collection.values.map((document) {
    if (document[field] is num) {
      document[field] = operatorMap[operator]!(document[field], value);
    }
    return document;
  }).toList();
  return List<Map<String, dynamic>>.from(calculatedDocuments);
}