bestWithWidth<T> static method
为一个宽度的屏幕选择其相应的样式,概念和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;
}