Real answer on a real question about how to break forEach in if
.
void main() {
final seq1 = [0, 1, 2];
final result = <int>[];
try {
seq1.forEach((e) {
if (e == 2) throw 'Stop this immediately';
result.add(e);
});
} catch (e) {
// What? Something happened?
}
print(result);
}
Result:
[0, 1]
Not the most practical option, but it works.
That is, fully functional, for your case (break forEach).
The answer fully answers your question.
Do you have any other question?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…