firstWhere method Null safety

E firstWhere (
  1. bool test(
    1. E element
  2. {E orElse(

    Returns the first element that satisfies the given predicate test.

    Iterates through elements and returns the first to satisfy test.

    If no element satisfies test, the result of invoking the orElse function is returned. If orElse is omitted, it defaults to throwing a StateError.


    E firstWhere(bool test(E element), {E Function()? orElse}) {
      int length = this.length;
      for (int i = 0; i < length; i++) {
        E element = elementAt(i);
        if (test(element)) return element;
        if (length != this.length) {
          throw new ConcurrentModificationError(this);
      if (orElse != null) return orElse();
      throw IterableElementError.noElement();