Sizer는 모바일, 웹 및 데스크톱 플랫폼에서 반응형 UI 디자인을 간소화하는 Flutter 패키지입니다. 기기의 화면 치수를 기반으로 한 논리적 단위를 사용하여 다양한 화면 크기와 방향에 자연스럽게 적응하는 레이아웃을 만드는 쉬운 방법을 제공합니다. Sizer를 사용하면 개발자는 화면 너비와 높이에 따라 크기를 정의할 수 있어 기기 유형이나 해상도에 관계없이 일관된 외관을 보장할 수 있습니다. 최소한의 설정으로 기존 프로젝트에 원활하게 통합되어 확장 가능하고 유지보수가 쉬운 사용자 인터페이스 구축에 이상적입니다.
사용 사례
크로스 플랫폼 반응형 앱 빌드
다양한 화면 크기에 맞는 적응형 레이아웃 만들기
모바일 및 데스크톱에서 일관된 UI 스케일링 보장
복잡한 미디어 쿼리 없이 반응형 디자인을 단순화
작은 휴대폰과 큰 데스크탑 화면 모두에서 작동하는 레이아웃 설계
주요 기능
자동 화면 크기 적응
모든 주요 플랫폼(안드로이드, iOS, 웹, macOS, Windows, 리눅스) 지원
사용하기 쉬운 스케일 기반 크기 조정
내장형 방향 처리
필요한 최소한의 보일러플레이트
적합한 대상
다양한 플랫폼을 대상으로 하는 개발자
UI 일관성을 우선시하는 팀
빠른 반응형 레이아웃 구현이 필요한 프로젝트
초보자가 반응형 Flutter 디자인을 배우는 중
다양한 기기에서 동적 확장이 필요한 앱
고려 사항
기존 하드코딩된 값의 초기 조정이 필요할 수 있습니다
일관된 디자인 시스템과 함께 사용하는 것이 가장 좋습니다
높은 사용자 정의 또는 비균일 확대 필요에 적합하지 않음
크기 기반 반응성에 국한되며, 레이아웃 구조 변경은 포함되지 않음
논리적 픽셀 스케일링 원칙을 이해해야 합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Sizer (Responsive UI solution for Mobile App,Web and Desktop)
Looking for Flutter development support? Let’s connect — available on WhatsApp and Email.
A Flutter package that simplifies responsive design by automatically adapting your app’s UI to any screen size — making responsiveness seamless and intuitive.
Same layout to look different in tablet and mobile, use the Device.screenType method:
Device.screenType == ScreenType.tablet
? Container( // Widget for Tablet
width: 100.w,
height: 20.5.h,
)
: Container( // Widget for Mobile
width: 100.w,
height: 12.5.h,
)
*Device.ScreenTypecan not be Desktop unless maxTabletWidth is set
Guideline
Sizer
maxMobileWidth - Maximum width of a mobile device
(If the device's width is larger than this, it will be categorized as a tablet) - Default value: 599
maxTabletWidth - Maximum width of a tablet device
(If the device's width is larger than this, it will be categorized as a desktop) - Optional: enables DesktopScreenType if enabled
Extensions
Adaptive.h() or .h - Calculated percentage of the device's height (40.h -> 40% of device's height)
Adaptive.w() or .w - Calculated percentage of the device's width (40.w -> 40% of device's width)
Adaptive.sp() or .sp - Calculated sp based on the device's pixel density and aspect ratio (See FAQ)
Adaptive.dp() or .dp - Calculated dp based on the device's pixel density (See FAQ)
*Note: Only use .sh and .sw if you want height and width to depend on the device's available height and width after applying SafeArea. Use .h and .w by default.
Adaptive.sh() or .sh - Calculated percentage of the remaining device's height after applying SafeArea
Adaptive.sw() or .sw - Calculated percentage of the remaining device's width after applying SafeArea
Device.boxConstraints - BoxConstraints of the device
Device.orientation - Screen Orientation of the device (portrait or landscape)
Device.screenType - Screen type of the device (mobile or tablet)
Device.aspectRatio - Aspect ratio of the device
Device.pixelRatio - Pixel density ratio of the device
Adaptive.cm() or .cm - The respective value in value in centimeters
Adaptive.mm() or .mm - The respective value in value in millimeters
Adaptive.Q() or .Q - The respective value in quarter-millimeters
Adaptive.inches() or .inches - The respective value in inches
Adaptive.pc() or .pc - The respective value in picas (1/6th of 1 inch)
Adaptive.pt() or .pt - The respective value in points (1/72th of 1 inch)
Adaptive.px() or .px - The respective value in pixels
Note
You need to import sizer package in order to access number.h, number.w, number.dp, and number.sp
Auto import in VSCode and Android Studio doesn't work for dart extension methods. Typing 10.h would not bring up auto import suggestion for this package
One workaround is to type Device so that the auto import suggestion would show up:
Why is dp not calculated using the device's screen density?
Since there is no way to obtain a device's physical width in inches, we could not calculate for screen density. Material Design's screen density calculation involves a device's physical width in inches. As an alternative, dp is calculated using the device's pixel ratio.
Community Support
If you have any suggestions or issues, feel free to open an issue
If you would like to contribute, feel free to create a PR