getBreakpoint static method

Breakpoint getBreakpoint(
  1. BuildContext context
)

Return Breakpoint based on layout width

Implementation

static Breakpoint getBreakpoint(BuildContext context) {
  Size screenSize = MediaQuery.of(context).size;

  var index = 0;
  for (var element in _range) {
    if (screenSize.width >= element.min && screenSize.width <= element.max) {
      break;
    }
    index++;
  }
  switch (index) {
    case 0:
      return Breakpoint.xs;
    case 1:
      return Breakpoint.sm;
    case 2:
      return Breakpoint.md;
    case 3:
      return Breakpoint.lg;
    case 4:
      return Breakpoint.xl;
    case 5:
      return Breakpoint.xxl;
    default:
      Breakpoint.md;
  }

  return Breakpoint.md; // as fallback
}