sized_context
컨텍스트를 통해 MediaQuery 크기 정보에 직접 액세스할 수 있으며, 크기 및 레이아웃을 위한 보조 메서드도 추가합니다.
BuildContext 인스턴스에 직접 MediaQuery 크기 정보를 제공하는 Flutter 코드 확장입니다. 또한 크기 조정 및 레이아웃용 보조 메서드도 추가합니다.
{"sdk":"flutter"}^1.0.0{"sdk":"flutter"}^2.0.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
With this extension package you can easily access the MediaQuery sizing info directly on the build context:
Size size = context.sizePx;
It also provides additional convenience methods like landscape state, diagonal screen size, inch-based measurements, screen type and percentage values:
bool isLandscape = context.isLandscape; //Instead of: MediaQuery.of(context).orientation == Orientation.landscape
bool isTablet = context.diagonalInches >= 7; //Get physical device size in inches
bool useSingleColumn = context.widthPx < 400; //Access .width and .height directly, no need to go through .size
double sidePadding = context.widthPercent(0.1); //Use percentages of width or height for sizing
dependencies:
sized_context: ^1.0.0+1
import 'package:sized_context/sized_context.dart';
bool isLandscape = context.isLandscape;
//PIXELS
Size size = context.sizePx;
double width = context.widthPx;
double height = context.heightPx;
double diagonalPx = context.diagonalPx;
//INCHES
Size sizeInInches = context.sizeInches;
double widthInInches = context.widthInches;
double heightInInches = context.heightInches;
double diagonalInInches = context.diagonalInches;
//PERCENTAGE
double widthPercent = context.widthPct(.1);
double heightPercent = context.heightPct(.25);
For convenience you can also access the MediaQueryData object directly, to get any other methods or properties:
EdgeInsets padding = context.mq.padding;
Size safeSize = context.mq.removePadding();
If you encounter any problems please open an issue. If you feel the library is missing a feature, please raise a ticket on Github and we'll look into it. Pull request are welcome.
MIT License