forWidth method

Breakpoint forWidth(
  1. double width, [
  2. Map<String, double> minWidths = const {}
])

The breakpoint width falls in: the last one, in order, whose min width is at or below it, else the first. minWidths (id → min width) moves some breakpoints' switch points (a node's or canvas's own, DESIGN.md §5.3); the order stays the set's, and a breakpoint it doesn't move starts no earlier than the one before it as moved (a node that moves desktop to 1200 isn't on a wider breakpoint at 1150).

Implementation

Breakpoint forWidth(double width, [Map<String, double> minWidths = const {}]) {
  var best = list.first;
  var floor = 0.0;
  for (var i = 1; i < list.length; i++) {
    final b = list[i];
    final own = minWidths[b.id];
    final start = own ?? (b.minWidth < floor ? floor : b.minWidth);
    if (own != null || start > floor) floor = start;
    if (width >= start) best = b;
  }
  return best;
}