Learn/Styling & Polish/Responsive & Adaptive Design

Responsive & Adaptive Design

Build layouts that adapt to different screen sizes and platforms

6 min~7 min read+35 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. MediaQuery - Reading Screen Information
  2. 2. LayoutBuilder - Responding to Parent Size
  3. 3. Flexible and Expanded for Proportional Sizing
  4. 4. Adaptive Navigation Pattern
  5. 5. Responsive + Adaptive Together
  6. 6. This Lesson In Simple Words
  7. 7. Your level focus
  8. 8. One practical habit
  9. 9. Deep Understanding Guide
  10. 10. Why this lesson matters
  11. 11. Study flow for better retention
  12. 12. Quick Glossary
  13. 13. Architecture Lens

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

Responsive & Adaptive Design

Flutter apps can run on phones, tablets, desktops, and the web, each with very different screen sizes. Responsive design means your layout adjusts smoothly to any screen width and height. Adaptive design goes a step further by changing the actual UI pattern based on the platform or device. For example, a phone might show a bottom navigation bar while a tablet shows a side navigation rail. This lesson covers MediaQuery for reading screen dimensions, LayoutBuilder for building widgets relative to their parent, and practical patterns for handling multiple screen sizes.

MediaQuery - Reading Screen Information

MediaQuery gives you access to the current screen size, orientation, text scale factor, padding for notches and system bars, and more. You access it through MediaQuery.of(context) and it returns a MediaQueryData object with all the information about the current display environment.

dart
1@override
2Widget build(BuildContext context) {
3 final screenWidth = MediaQuery.of(context).size.width;
4 final screenHeight = MediaQuery.of(context).size.height;
5 final orientation = MediaQuery.of(context).orientation;
6 final topPadding = MediaQuery.of(context).padding.top; // notch/status bar
7 final textScale = MediaQuery.of(context).textScaleFactor;
8
9 // Responsive layout based on width
10 if (screenWidth >= 1200) {
11 return DesktopLayout(); // wide screens
12 } else if (screenWidth >= 600) {
13 return TabletLayout(); // medium screens
14 } else {
15 return MobileLayout(); // small screens
16 }
17}

LayoutBuilder - Responding to Parent Size

While MediaQuery gives you the full screen size, LayoutBuilder tells you the exact space available to a specific widget from its parent. This is more useful when building reusable components that might be placed inside different containers at different sizes.

dart
1// LayoutBuilder adapts to the available space
2LayoutBuilder(
3 builder: (context, constraints) {
4 // constraints.maxWidth = available width from parent
5 if (constraints.maxWidth > 600) {
6 // Wide: show grid with 3 columns
7 return GridView.builder(
8 gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
9 crossAxisCount: 3,
10 crossAxisSpacing: 16,
11 mainAxisSpacing: 16,
12 ),
13 itemCount: items.length,
14 itemBuilder: (_, i) => ItemCard(item: items[i]),
15 );
16 } else {
17 // Narrow: show simple list
18 return ListView.builder(
19 itemCount: items.length,
20 itemBuilder: (_, i) => ItemTile(item: items[i]),
21 );
22 }
23 },
24)

Flexible and Expanded for Proportional Sizing

Instead of using fixed pixel values, use Flex widgets to make children take up a proportion of the available space. Expanded takes all remaining space, while Flexible takes only as much as it needs up to the available space. You can combine multiple Expanded widgets with different flex values to create ratio-based layouts.

dart
1// Proportional layout using flex
2Row(
3 children: [
4 // Takes 2/3 of the row width
5 Expanded(
6 flex: 2,
7 child: ContentPanel(),
8 ),
9 const SizedBox(width: 16),
10 // Takes 1/3 of the row width
11 Expanded(
12 flex: 1,
13 child: SidePanel(),
14 ),
15 ],
16)
17
18// FractionallySizedBox for percentage-based sizing
19FractionallySizedBox(
20 widthFactor: 0.8, // 80% of parent width
21 child: ElevatedButton(
22 onPressed: () {},
23 child: const Text('Wide Button'),
24 ),
25)
26
27// AspectRatio to maintain proportions
28AspectRatio(
29 aspectRatio: 16 / 9, // width:height ratio
30 child: Container(color: Colors.blue),
31)

Adaptive Navigation Pattern

A common pattern is to show different navigation styles based on screen width. Phones get a BottomNavigationBar, tablets get a NavigationRail on the side, and desktops get a full NavigationDrawer that is always visible. Here is how to build that.

dart
1class AdaptiveScaffold extends StatefulWidget {
2 @override
3 State<AdaptiveScaffold> createState() => _AdaptiveScaffoldState();
4}
5
6class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
7 int _selectedIndex = 0;
8
9 final _pages = const [
10 HomeScreen(),
11 SearchScreen(),
12 ProfileScreen(),
13 ];
14
15 @override
16 Widget build(BuildContext context) {
17 final width = MediaQuery.of(context).size.width;
18
19 // Desktop: permanent side drawer
20 if (width >= 1200) {
21 return Scaffold(
22 body: Row(
23 children: [
24 NavigationDrawer(
25 selectedIndex: _selectedIndex,
26 onDestinationSelected: (i) => setState(() => _selectedIndex = i),
27 children: const [
28 NavigationDrawerDestination(icon: Icon(Icons.home), label: Text('Home')),
29 NavigationDrawerDestination(icon: Icon(Icons.search), label: Text('Search')),
30 NavigationDrawerDestination(icon: Icon(Icons.person), label: Text('Profile')),
31 ],
32 ),
33 Expanded(child: _pages[_selectedIndex]),
34 ],
35 ),
36 );
37 }
38
39 // Tablet: navigation rail on the side
40 if (width >= 600) {
41 return Scaffold(
42 body: Row(
43 children: [
44 NavigationRail(
45 selectedIndex: _selectedIndex,
46 onDestinationSelected: (i) => setState(() => _selectedIndex = i),
47 labelType: NavigationRailLabelType.all,
48 destinations: const [
49 NavigationRailDestination(icon: Icon(Icons.home), label: Text('Home')),
50 NavigationRailDestination(icon: Icon(Icons.search), label: Text('Search')),
51 NavigationRailDestination(icon: Icon(Icons.person), label: Text('Profile')),
52 ],
53 ),
54 const VerticalDivider(width: 1),
55 Expanded(child: _pages[_selectedIndex]),
56 ],
57 ),
58 );
59 }
60
61 // Phone: bottom navigation bar
62 return Scaffold(
63 body: _pages[_selectedIndex],
64 bottomNavigationBar: BottomNavigationBar(
65 currentIndex: _selectedIndex,
66 onTap: (i) => setState(() => _selectedIndex = i),
67 items: const [
68 BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
69 BottomNavigationBarItem(icon: Icon(Icons.search), label: 'Search'),
70 BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
71 ],
72 ),
73 );
74 }
75}

Common Breakpoints

💡 Common Breakpoints

A widely used set of breakpoints is: below 600 pixels for phones, 600 to 1199 pixels for tablets, and 1200 pixels and above for desktops. These are not strict rules but a good starting point. Always test your app on multiple screen sizes.

Avoid Hardcoded Sizes

⚠️ Avoid Hardcoded Sizes

Never use fixed pixel widths for layouts that need to fill the screen. Use Expanded, Flexible, FractionallySizedBox, or MediaQuery to build layouts that adapt to any screen size. Hardcoded widths cause overflow errors on smaller screens and wasted space on larger ones.

Responsive + Adaptive Together

Responsive sizing handles dimensions. Adaptive patterns handle interaction models.

Use both:

  • responsive for spacing and component sizing
  • adaptive for navigation and platform conventions

This combination creates UIs that feel natural on every device class.

Cross-Device QA Checklist

  • No overflow or clipped content at narrow widths.
  • Navigation pattern matches screen class expectations.
  • Touch and pointer interactions both feel correct.
  • Critical user flows remain equally discoverable across layouts.

This Lesson In Simple Words

Build layouts that adapt to different screen sizes and platforms. Widgets are reusable UI blocks. You combine them like LEGO pieces to build screens.

Your level focus

Connect each concept to real app features you can build.

One practical habit

Sketch the widget tree first, then code from top to bottom.

Deep Understanding Guide

Why this lesson matters

Most Flutter productivity comes from understanding layout rules and composing widgets cleanly.

Study flow for better retention

  1. Map the lesson to one screen, one user action, and one expected output.
  2. When a UI bug appears, inspect constraints and parent-child relations before changing random values.
  3. If you can choose between two approaches and explain why, you are improving.

Common Mistakes To Avoid

  • Nesting too many widgets without extracting reusable pieces.
  • Ignoring constraints and guessing with random SizedBox heights.
  • Using one giant build method for unrelated UI sections.
  • Putting heavy calculations directly in build methods.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Build one card layout with Row/Column and rebuild it using Stack for comparison.
  • Split a large widget into 3 smaller widgets with clear responsibilities.
  • Use const constructors where possible and observe rebuild behavior.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "What is the difference between MediaQuery and LayoutBuilder?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.
  • context: A handle to widget location and inherited data in the tree.
  • build: The method that describes UI for the current state.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Architecture Lens

Good widget composition is architecture at UI level, because it decides testability and reuse.

As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.

Lesson Completion Checklist

  • I can explain "Responsive & Adaptive Design" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Nesting too many widgets without extracting reusable pieces.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

What is the difference between MediaQuery and LayoutBuilder?

MediaQuery.of(context).size gives the entire screen dimensions. LayoutBuilder constraints give the exact space the parent has allocated to this widget, which may be smaller.

Which widget makes a child take up a fraction of the available space?

FractionallySizedBox uses widthFactor and heightFactor to size the child as a percentage of the available space.

What navigation widget is best for tablet-sized screens?

NavigationRail is a vertical strip of navigation icons on the side, designed for medium-width screens like tablets where a bottom bar wastes too much vertical space.

What does Expanded with flex: 2 mean in a Row?

The flex factor determines the proportion of remaining space each Expanded widget gets. flex: 2 takes twice the space of flex: 1.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue