addRowWhere method

void addRowWhere(
  1. bool test(
    1. T value
    ),
  2. T value, {
  3. bool after = true,
  4. bool firstOnly = true,
})

Insert value adjacent to rows matching testafter the match by default, or before it. With firstOnly (default) only the first match is used; otherwise value is inserted next to every match.

Implementation

void addRowWhere(bool Function(T value) test, T value, {bool after = true, bool firstOnly = true}) {
  _structural(() {
    final hits = <int>[];
    for (var i = 0; i < _all.length; i++) {
      if (test(_all[i])) {
        hits.add(i);
        if (firstOnly) break;
      }
    }
    for (final i in hits.reversed) {
      _all.insert(after ? i + 1 : i, value);
    }
  });
}