Sub topic 1
Responsive vs adaptive: what you are designing for
A Flutter app rarely runs in one fixed place. The same code may run on a phone held upright, a tablet in split-screen, a resizable desktop window, or a browser tab that the user drags to any width. This chapter defines the two terms used for that problem, responsive and adaptive. It also sets up the mental model that the rest of the tutorial builds on.
Prerequisites
This chapter assumes you can do the following:
- Read basic Dart, including Dart 3
switchexpressions. - Build widget trees with
StatelessWidgetandStatefulWidget. - Use
Row,Column,ScaffoldandListView. - Run a Flutter app on at least one device, emulator or desktop target.
You do not need prior knowledge of MediaQuery or LayoutBuilder. Later chapters cover both in detail. This chapter only previews them.
The problem: one codebase, many windows
A layout that looks right at 400 logical pixels wide can break at 1400. Text lines become too long to read. A single column leaves large empty margins. A bottom navigation bar stretches across a whole monitor.
A logical pixel is Flutter's device-independent unit. Layout code works in logical pixels, and Flutter converts them to physical pixels using the device pixel ratio. The width in logical pixels is the number you will compare against throughout this tutorial.
Two things change from one device to another:
- Space. The window is larger or smaller. On desktop and web it can change continuously while the app runs. On mobile it also changes with rotation, split-screen and foldable hinges.
- Context. The platform has its own conventions, and the user may operate the app with a finger, a mouse or a keyboard.
Responsive and adaptive design are two answers to these two kinds of change.
Definitions
A responsive layout stretches, shrinks and reflows to fit the space it is given. The widget tree keeps the same structure, and sizes and positions are computed from the available space. A Wrap that moves items onto a new line when the row is full is responsive.
An adaptive layout makes a discrete choice. It picks one of several designs, or swaps one widget for another, depending on the situation. Showing a NavigationBar on narrow windows and a NavigationRail on wide windows is adaptive. So is using a different control style on iOS than on Android.
| Row | Responsive | Adaptive |
|---|---|---|
| Core idea | Fit the available space | Choose the right design for the situation |
| Change is | Continuous | Stepwise, at thresholds |
| Widget tree | Same structure, different sizes | Different widgets or arrangements |
| Typical tools | `Expanded`, `Flexible`, `Wrap`, `AspectRatio` | Breakpoints, `LayoutBuilder`, platform checks |
| Example | A tag list that reflows | Bottom bar on phones, rail on tablets |
Real apps use both. A well-built screen is usually adaptive at the top level and responsive inside each variant. For example, the app shell switches between bar and rail at a threshold, and the page inside it flexes smoothly between thresholds.
A responsive example
This app shows a list of chips. Nothing in the code mentions a screen size. Wrap places chips left to right and starts a new line when the next chip does not fit.
import 'package:flutter/material.dart';
void main() => runApp(
const MaterialApp(home: Scaffold(body: TagCloud())),
);
class TagCloud extends StatelessWidget {
const TagCloud({super.key});
static const _tags = [
'Flutter',
'Dart',
'Layout',
'Widgets',
'Constraints',
'Testing',
];
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (final tag in _tags) Chip(label: Text(tag)),
],
),
);
}
}Resize a desktop window while it runs and the chips reflow at every width. The structure never changes, so the layout is responsive.
An adaptive example
Now consider a profile header. On a narrow space, the avatar should sit above the text. On a wide space, it should sit beside the text. Neither Row nor Column can do both, so the code chooses between them.
import 'package:flutter/material.dart';
void main() => runApp(
const MaterialApp(home: Scaffold(body: ProfileHeader())),
);
class ProfileHeader extends StatelessWidget {
const ProfileHeader({super.key});
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final wide = constraints.maxWidth >= 600;
const avatar = CircleAvatar(radius: 40, child: Icon(Icons.person));
const details = Text('Ada Lovelace\nMathematician');
return Padding(
padding: const EdgeInsets.all(16),
child: wide
? const Row(
children: [avatar, SizedBox(width: 24), details],
)
: const Column(
children: [avatar, SizedBox(height: 16), details],
),
);
},
);
}
}The widget tree is different on each side of the 600 pixel threshold, so this layout is adaptive. LayoutBuilder reports the width this widget is allowed to use. Chapter 5 covers it in detail. The number 600 is a breakpoint, and chapter 6 shows how to choose breakpoints systematically.
What "adaptive" covers beyond size
Size is the most common reason to adapt, but not the only one. The Topic Spine for this tutorial separates three kinds of adaptation:
- Layout adaptation. Different arrangements for different amounts of space, such as one pane versus two panes.
- Platform adaptation. Controls and behaviors that match what users expect on each operating system, such as scroll physics, dialog style and back navigation.
- Input adaptation. Hover states, right-click menus, keyboard shortcuts and larger tap targets, depending on whether the user has a touch screen, a mouse or a keyboard.
This chapter introduces the vocabulary. Later chapters cover each kind in turn.
Design for window size, not device type
A common beginner mistake is to treat "phone", "tablet" and "desktop" as the categories to design for. These categories do not hold up:
- A tablet app may run in a split-screen window as narrow as a phone.
- A desktop window can be resized to phone width.
- A foldable phone changes its usable area when it is unfolded.
- A web page can be any width the browser gives it.
Because of this, the reliable input to a layout decision is the space available, measured in logical pixels, and not the kind of hardware. Checks such as Platform.isAndroid answer a different question, which is which operating system conventions apply. They do not say how much room you have. Mixing the two questions is a frequent source of layouts that break in multi-window mode.
Where the information comes from
Flutter gives you two main ways to learn how much space you have, and you will compare them in chapters 4 and 5:
MediaQuery.sizeOf(context)returns the size of the whole window (strictly, the nearestMediaQuery). It is simple, but it ignores any narrower parent your widget may sit in, such as a side panel.LayoutBuilderreturns the constraints from the widget's own parent. It reflects the space the widget will really get.
Both rest on Flutter's constraints model. Parents pass constraints down, and children choose a size within them and pass it back up. Chapter 2 explains that model, because every responsive and adaptive technique is a way of working with it.
Choosing an approach
As a first rule of thumb, ask three questions about each piece of UI:
- Does the same structure work at any width, if sizes just change? Use responsive tools (
Expanded,Wrap, a grid with a maximum tile width). - Does the structure itself need to differ, such as bar versus rail or one pane versus two? Use an adaptive switch at a breakpoint.
- Does the difference depend on platform or input, not space? Use platform or input adaptation.
Prefer the responsive option when it works. It has no thresholds to maintain and no variants to test. Add adaptive switches only where flexing cannot produce a good design.
Trade-offs to keep in mind
- More variants mean more testing. Each adaptive branch is another layout to check. Chapter 13 shows how to test at specific window sizes.
- Thresholds can flicker. If a window hovers around a breakpoint, a stateful subtree may be rebuilt as the tree changes shape. Keep important state above the switch.
- Responsive code can still be wrong. A layout that stretches without limit remains hard to read on a very wide window, so flexible does not mean finished.
Exercise
A news app shows article cards in a Wrap that reflows as the window is resized. On windows at least 840 logical pixels wide, the team also wants a sidebar of categories that does not exist on narrower windows. Which part is responsive and which part is adaptive, and what should decide whether the sidebar appears?
Show answer
The Wrap of cards is responsive: the structure stays the same and only positions change with the space. The sidebar is adaptive: it is a different widget structure chosen at a threshold. The decision should depend on the width of the space the layout actually receives (for example through LayoutBuilder constraints or MediaQuery.sizeOf), compared with 840, and not on whether the device is a phone, tablet or desktop.
Exercise
Why is checking Platform.isAndroid a poor way to decide between a one-pane and a two-pane layout?
Show answer
Platform.isAndroid says which operating system is running, not how much space the app has. An Android tablet in split-screen may be as narrow as a phone, and an Android foldable can change its width when unfolded. The layout choice should be based on the available width.