bestWithWidth<T> static method

T bestWithWidth<T>(
  1. double screenWidth, {
  2. required T min,
  3. T? sm,
  4. T? md,
  5. T? lg,
  6. T? xl,
  7. T? xxl,
})

为一个宽度的屏幕选择其相应的样式,概念和tailwindcss相似 屏幕宽度落在哪档的计算参考byScreen

Implementation

static T bestWithWidth<T>(double screenWidth, {required T min, T? sm, T? md, T? lg, T? xl, T? xxl}) {
  ScreenSize now = byScreen(screenWidth);
  List<(ScreenSize, T?)> options = [
    (ScreenSize.xxl, xxl),
    (ScreenSize.xl, xl),
    (ScreenSize.lg, lg),
    (ScreenSize.md, md),
    (ScreenSize.sm, sm),
  ];
  for (var (breakpoint, option) in options) {
    // 未提供某档专用样式的忽略
    if (option == null) {
      continue;
    }
    // 专用样式落在此档
    if (breakpoint.minWidth <= now.minWidth) {
      return option;
    }
  }
  return min;
}