Expert · Responsive design and testing · topic 39 of 50 · 35 min
Responsive and adaptive design
Explanation
Why responsive?
One Flutter codebase can run on a 5-inch budget phone, a foldable, a 12-inch tablet, a laptop browser and a desktop window that the user resizes. A layout designed only for one phone looks stretched or cramped elsewhere. Responsive design means the layout responds to the available space; adaptive design also respects platform conventions and input methods, such as hover effects and keyboard shortcuts on desktop.
Reading the size
| Tool | Gives you | Use when |
|---|---|---|
| MediaQuery.sizeOf(context) | The whole window size | Choosing the overall page structure |
| LayoutBuilder | The constraints given to this widget | A reusable widget that adapts to its own space |
| OrientationBuilder | Portrait or landscape | Small orientation-specific tweaks |
| MediaQuery.paddingOf(context) | Notch and system bar insets | Rarely directly; SafeArea handles it |
MediaQuery.sizeOf(context) is preferred over MediaQuery.of(context).size because it rebuilds only when the size changes, not when other MediaQuery values (like the keyboard insets) change.
Breakpoints
A breakpoint is a width at which the layout changes. Material Design's window size classes are a good guide: compact (under 600 dp wide, most phones in portrait), medium (600 to 840, small tablets and unfolded foldables) and expanded (840 and above, large tablets and desktops).
class OrdersPage extends StatelessWidget {
const OrdersPage({super.key});
@override
Widget build(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
if (width < 600) {
return const OrdersList(); // phone: list only; tap opens details
}
return const Row(
children: [
SizedBox(width: 360, child: OrdersList()), // tablet/desktop: list and details side by side
VerticalDivider(width: 1),
Expanded(child: OrderDetails()),
],
);
}
}LayoutBuilder for reusable widgets
LayoutBuilder(
builder: (context, constraints) {
final columns = constraints.maxWidth > 900 ? 4 : constraints.maxWidth > 600 ? 3 : 2;
return GridView.count(crossAxisCount: columns, children: const [/* tiles */]);
},
)Other helpful tools
- SafeArea: keeps content away from notches, rounded corners and system bars.
- Wrap: lets chips or buttons flow onto the next line instead of overflowing.
- Flexible and Expanded instead of fixed widths (module 5).
- ConstrainedBox(constraints: BoxConstraints(maxWidth: 600)): keeps forms and articles readable on wide screens.
- Adaptive widgets like Switch.adaptive and CircularProgressIndicator.adaptive show iOS-style controls on Apple platforms.
Text scaling and accessibility
Many users, especially older people, increase font size in system settings. Flutter scales text automatically. Test your screens at the largest text size: avoid fixed heights that cut text off, allow lines to wrap, and let buttons grow. Good contrast and large tap targets (at least 48 x 48) help everyone.
Common mistakes
- Fixed pixel widths copied from a phone design: overflow on small phones, emptiness on tablets.
- Using screen width deep inside small widgets instead of LayoutBuilder constraints.
- Forgetting SafeArea: content hidden behind the notch or the gesture bar.
- Never testing landscape, a tablet emulator, the web or large fonts.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Responsive and adaptive design · 1/6
Responsive layouts fit the available space. Adaptive layouts also fit the platform and input.
Prefer a video by a teacher? Find free videos on “flutter responsive design layoutbuilder mediaquery breakpoints adaptive” on YouTube ↗
In real life: A clinic appointments app on reception desktops and phones
A clinic chain uses one Flutter app for patients on phones and for receptionists on desktop browsers. On phones, the appointments list opens details on a new screen. On wide screens, the list and the selected appointment appear side by side, and the booking form is limited to 600 pixels wide so it stays easy to read. One codebase, two comfortable experiences.
Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: const BookingForm(),
),
)Practice (0/3 done)
Which tool tells a reusable card widget how much space it was given?
Which widget keeps content away from a phone's notch and gesture bar?
Make a product catalogue responsive: a grid with 2 columns on phones, 3 on small tablets and 4 on wide screens using LayoutBuilder; a details pane beside the grid when the window is 840 or wider; SafeArea; and a search field limited to 600 wide. Test on a phone, a tablet emulator, landscape and Chrome (resize the window).
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Unit testsResponsive design and testing · same module
- Widget testsResponsive design and testing · same module
- Integration tests and CIResponsive design and testing · same module
- Accessibility and adaptive layoutsKotlin and Android App Development · Permissions, Material 3 and polish
- Responsive design and media queriesFrontend Web Development · CSS layout and responsive design
- Planning screens and user flowsFull-Stack Development · Planning an app
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which width class do most phones in portrait belong to?
Answer: Compact (under 600)
Most phones are under 600 dp wide in portrait.
Why prefer MediaQuery.sizeOf(context) over MediaQuery.of(context).size?
Answer: It rebuilds only when the size changes
Fewer unnecessary rebuilds.
What is the difference between responsive and adaptive?
Answer: Responsive fits the space; adaptive also fits platform conventions and input
Both matter on multi-platform apps.
What should you check with large system font sizes?
Answer: That text is not cut off and buttons grow
Many users rely on large text.
Which window width class do most phones in portrait have?Related
How should you choose breakpoints?Related
Answer: Where your content starts to look wrong
Breakpoints should follow the content, not specific devices.
What is a widget?Related
Answer: An immutable description of part of the UI
Flutter rebuilds the screen from widgets.
Which is an accessibility problem?Related
Answer: An error shown only by a red border, with no text
Colour alone does not reach colour-blind users or screen readers. Add a text message too.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “Responsive design and testing” before its exam: Unit tests, Widget tests, Integration tests and CI.
- Module 10 exam: Responsive design and testing · 12 questions · 25 min, without help. 4 topics of this module still to finish first.
- Then the next module, Publishing to the stores and the web. 50 topics left in the course before the final exam.