breakpoint method

  1. @nonVirtual
B? breakpoint(
  1. double containerWidth
)

Returns null if container width is smaller than the smallest breakpoint.

Implementation

@nonVirtual
B? breakpoint(double containerWidth) {
  if (containerWidth < breakpoints.first.minWidth) {
    // Ex. containerWidth is 50dp but smallest breakpoint is 100dp,
    return null;
  }

  return breakpoints.firstWhere((breakpoint) {
    final nextBreakpoint =
        breakpoints.firstWhereOrNull((bp) => bp > breakpoint);

    if (nextBreakpoint == null) {
      // Returns the biggest breakpoint.
      return true;
    }

    return containerWidth >= breakpoint.minWidth &&
        containerWidth < nextBreakpoint.minWidth;
  });
}