forWidth method
The entry for width: the one whose switch point (by breakpoints) is
the highest at or below it, else the narrowest. Null when there are
none.
Implementation
CanvasBreakpoint? forWidth(double width, Breakpoints breakpoints) {
if (isEmpty) return null;
CanvasBreakpoint? best, narrowest;
double bestMin = double.negativeInfinity, narrowestMin = double.infinity;
for (final c in this) {
final min = c.minWidthIn(breakpoints);
if (min < narrowestMin) {
narrowest = c;
narrowestMin = min;
}
if (width >= min && min > bestMin) {
best = c;
bestMin = min;
}
}
return best ?? narrowest;
}