current property

  1. @override
PhoneNumberMatch current
override

The current element.

If the iterator has not yet been moved to the first element (moveNext has not been called yet), or if the iterator has been moved past the last element of the Iterable (moveNext has returned false), then current is unspecified. An Iterator may either throw or return an iterator specific default value in that case.

The current getter should keep its value until the next call to moveNext, even if an underlying collection changes. After a successful call to moveNext, the user doesn't need to cache the current value, but can keep reading it from the iterator.

final colors = ['blue', 'yellow', 'red'];
var colorsIterator = colors.iterator;
while (colorsIterator.moveNext()) {
  print(colorsIterator.current);
}

The output of the example is:

blue
yellow
red

Implementation

@override
PhoneNumberMatch get current {
  // Check the state and find the next match as a side-effect if necessary.
  if (!moveNext()) {
    throw Exception('No such element');
  }

  // Don't retain that memory any longer than necessary.
  PhoneNumberMatch result = _lastMatch!;
  _lastMatch = null;
  _state = PhoneNumberMatcherState.notReady;
  return result;
}