Responsive Design: MediaQuery, LayoutBuilder and Adaptive UI

Google Flutter 11 min min read Updated: Nov 16, 2026 Intermediate
Responsive Design: MediaQuery, LayoutBuilder and Adaptive UI
Intermediate Topic 9 of 9

One App, Many Screens

Your app will run on tiny phones, big tablets, foldables, browsers and desktops. A responsive app adapts its layout to the space it gets.

MediaQuery: Ask About the Screen

dart final size = MediaQuery.sizeOf(context); print(size.width); // logical pixels print(size.height); final orientation = MediaQuery.orientationOf(context); final padding = MediaQuery.paddingOf(context); // notch and status bar

SafeArea

SafeArea keeps your content away from the notch, status bar and the home indicator.

dart Scaffold( body: SafeArea( child: Text('I am never hidden by the notch'), ), )

LayoutBuilder: Use the Space of the Parent

LayoutBuilder tells you how much space the parent gives you. This is better than the screen size, because a widget may sit in a narrow panel on a wide screen.

dart class ResponsiveHome extends StatelessWidget { const ResponsiveHome({super.key}); @override Widget build(BuildContext context) { return LayoutBuilder( builder: (context, constraints) { if (constraints.maxWidth >= 900) { return const DesktopLayout(); } else if (constraints.maxWidth >= 600) { return const TabletLayout(); } return const PhoneLayout(); }, ); } }
Width (logical px)Typical deviceLayout idea
Under 600PhoneOne column, bottom navigation
600 to 900Tablet or foldableTwo columns, navigation rail
Over 900Desktop, big webSide menu plus content, max width

A Master-Detail Example

dart LayoutBuilder( builder: (context, c) { final wide = c.maxWidth >= 700; return Row( children: [ const Expanded(flex: 1, child: ItemList()), if (wide) const Expanded(flex: 2, child: ItemDetail()), ], ); }, )

Other Helpful Widgets

WidgetUse
Flexible / ExpandedShare available space
AspectRatioKeep a width to height ratio, such as 16 / 9 for videos
FractionallySizedBoxUse a fraction of the parent size
ConstrainedBoxSet minimum and maximum size
WrapMove items to the next line when full
OrientationBuilderBuild different UI for portrait and landscape
dart // Center content with a maximum width on big screens Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 600), child: const LoginForm(), ), )

Text Scale and Accessibility

Users can make the text bigger in the phone settings. Test your screens with large text, and avoid fixed heights for text containers.

Testing Different Sizes

  • Run the app in Chrome and resize the window
  • Use the device preview in DevTools
  • Test portrait and landscape on emulators
Rule of thumb: Avoid hard-coded pixel sizes for big layout parts. Prefer Expanded, Flexible, Wrap and breakpoints.

Conclusion

Responsive design is mostly about flexible widgets and a few breakpoints. Use LayoutBuilder for local decisions and MediaQuery for screen information.

Quick Summary: Use SafeArea, flexible widgets, LayoutBuilder with breakpoints and ConstrainedBox for adaptive layouts.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators