angular-dart

In angular dart is there a way to break early from a "foreach" loop


I saw that this is already answered for javascript but is there a way to break out of an forEach loop in angular dart.

  bool hasValue() {
    bool result = false;
    periods.forEach((item) {
      if (item.hasValue()) {
        result = true;
        //PENDING...Break out of loop early
      }
    });

    return result;
  }

Solution

  • As far as I know, you cannot break forEach loop.

    You can try this code instead:

     for(var item in items) {
      final value = item['unit_value'];
      if (value.isNotEmpty) {
        break;
      }
    }