get method

Counter get(
  1. String? name,
  2. CounterType type
)
inherited

Gets a counter specified by its name. It counter does not exist or its type doesn't match the specified type it creates a new one.

  • name a counter name to retrieve.
  • type a counter type. Return an existing or newly created counter of the specified type.

Implementation

Counter get(String? name, CounterType type) {
  if (name == null || name == '') {
    throw Exception('Name cannot be null');
  }

  _resetIfNeeded();

  var counter = _cache[name];

  if (counter == null || counter.type != type) {
    counter = Counter(name, type);
    _cache[name] = counter;
  }

  return counter;
}