Search packages, repositories and app categories

Package detailsv1.0.0+4

sized_context

Access MediaQuery sizing info directly on the context, also adds some helper methods for sizing and layout.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
60
Likes
195
Pub points
160

Install package

flutter pub add sized_context

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The sized_context package provides direct access to MediaQuery sizing information through the context, simplifying responsive UI development. It extends theBuildContext with useful helper methods for calculating sizes, spacing, and layout dimensions based on screen metrics. This eliminates the need to repeatedly call MediaQuery.of(context) throughout the widget tree. Ideal for building adaptable layouts across different device sizes and orientations.

Use cases

  • Responsive layout design
  • Cross-platform UI adaptation
  • Dynamic widget sizing
  • Simplifying MediaQuery usage
  • Consistent spacing across devices

Key features

  • Direct context-based sizing
  • Built-in size calculation helpers
  • Reduces boilerplate code
  • Supports all Flutter platforms
  • Easy integration with existing widgets

Suitable for

  • Developers building responsive apps
  • Teams prioritizing UI consistency
  • Projects targeting multiple platforms
  • Apps requiring dynamic layouts

Considerations

  • Requires context access
  • May increase build complexity if overused
  • Not needed for simple static layouts
  • Limited to sizing-related functionality
  • Best used in conjunction with other layout packages

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

✥ Sized Context - Easy responsive sizing

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

🔨 Installation

dependencies:
  sized_context: ^1.0.0+1
⚙ Import
import 'package:sized_context/sized_context.dart';

🕹️ Usage

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();

🐞 Bugs/Requests

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.

👏 Thanks

  • Thanks to reddit user der_kobold for the idea to turn this into an extension!

📃 License

MIT License

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package