반응형
방법 1.
class FormFactor {
static double desktop = 900;
static double tablet = 600;
static double handset = 300;
}
ScreenType getFormFactor(BuildContext context) {
// Use .shortestSide to detect device type regardless of orientation
double deviceWidth = MediaQuery.of(context).size.shortestSide;
if (deviceWidth > FormFactor.desktop) return ScreenType.Desktop;
if (deviceWidth > FormFactor.tablet) return ScreenType.Tablet;
if (deviceWidth > FormFactor.handset) return ScreenType.Handset;
return ScreenType.Watch;
}
방법 2.
enum ScreenSize { Small, Normal, Large, ExtraLarge }
ScreenSize getSize(BuildContext context) {
double deviceWidth = MediaQuery.of(context).size.shortestSide;
if (deviceWidth > 900) return ScreenSize.ExtraLarge;
if (deviceWidth > 600) return ScreenSize.Large;
if (deviceWidth > 300) return ScreenSize.Normal;
return ScreenSize.Small;
}
끝!
반응형
'Flutter(플러터)' 카테고리의 다른 글
Android/iOS 무료 아이콘 만들기 사이트 (0) | 2023.07.17 |
---|---|
[플러터/Flutter] Dart, Flutter Timestamp (0) | 2023.06.30 |
[플러터/Flutter] 플러터에서 iOS, Android 강제 종료하기 (0) | 2023.06.22 |
[플러터/Flutter] Flutter Web Error: Unsupported operation: Platform._operatingSystem 발생 해결 방법 (0) | 2023.06.16 |
[플러터/Flutter] Android and iOS setup Internet Permission. (0) | 2023.06.16 |