Flutter Layout, Constraints and Navigation Basics

A museum visitor opens a guided tour on their phone. The first stop is called “Blue Room”. It fits easily on one line. The second is “Light Through the Windows of the Old Workshop”. At a larger text size, the last few words run into the arrow at the edge of the screen. The visitor also wants to tap that title, read the guide, and return to the same place in the tour.

These are two different jobs. Layout decides how much room the title and arrow get and where they sit. Constraints are the size limits Flutter uses to make that decision. Navigation decides which screen opens after a tap and where Back takes the visitor. You can understand all three by following that one museum stop.

How does Flutter decide how big a widget can be?

Think of a museum label that must fit inside a frame. The printer can wrap a long title onto two lines, but the frame sets the maximum width. Once the label has a size, someone decides where to place it inside the display. Flutter does something similar with the boxes that make up a screen.

  1. The parent gives the child size limits. These can include a minimum and maximum width and a minimum and maximum height.
  2. The child chooses a size within those limits. A text label given a narrow width may need more height to display all its words.
  3. The parent positions the child. It might place the label at the start of a row, centre it, or put it underneath another widget.

This explains a common beginner surprise. Suppose an area requires its child to be exactly 300 logical pixels wide. Putting a SizedBox(width: 120) directly inside it still produces a 300-wide box. Put a Center between them and the result changes: the centre widget occupies the available space and lets its child choose a smaller width. The same request for 120 can now be honoured.

Developers call the first case a tight constraint: the minimum and maximum for that dimension are equal. A loose constraint allows the child to be smaller, down to zero, while still respecting the maximum. When a width setting seems to have no effect, inspect the parent that supplied the limits. The Flutter widget tree shows you which parent to look at.

Why does a long title overflow inside a Row?

A Row places children horizontally. A Column places them vertically. Neither arrangement, by itself, tells a long piece of text how much room to leave for its neighbour.

In a horizontal row, Flutter first measures children that have no share of the remaining width assigned to them. Give the title and the arrow to the row as ordinary children, and the title can ask for enough space to display itself on one line. With “Blue Room”, that happens to work. With the workshop title, the children together can be wider than the row. In debug mode, Flutter may show a yellow-and-black overflow stripe.

Wrap the title in Expanded. The row can then allocate space to the arrow and gap first, and give the remaining width to the title. If the row has 300 logical pixels inside it, the arrow takes 24 and the gap takes 12, the title gets 264. Now the text has a finite width at which to wrap. Leaving the row free to grow taller keeps the full artwork name readable.

How does Flutter move from the list to a detail screen?

A route represents a destination in the app. Flutter’s Navigator keeps a stack of routes. Picture two museum guide cards lying on a desk. The tour list is on the bottom. Opening an artwork places its detail card on top. Lifting that card reveals the list that was already underneath.

  • Navigator.push() adds the detail route on top of the list route.
  • Navigator.pop() removes the top route and reveals the previous one.

This distinction matters when you implement Back. If the button opens a fresh tour list with another push(), the screens can look correct for a moment. But press Back again and the visitor lands on the detail page they thought they had left. Returning with pop() gives the visitor the history they expect.

A Flutter example that handles both the title and the return trip

The following example is a complete lib/main.dart for a Flutter 3.50 project using material_ui. Look for three lines first: Expanded sizes the title, Navigator.push opens the selected stop, and Navigator.pop returns to the tour.

import 'package:material_ui/material_ui.dart';

void main() { runApp(const MaterialApp(home: TourPage())); }

const tourStops = { 'Blue Room': 'Stand in the doorway and compare the two shades of blue.', 'Light Through the Windows of the Old Workshop': 'Look at the shadows on the floor before looking up at the windows.', 'The Courtyard': 'Walk to the centre to see how the three entrances line up.', };

class TourPage extends StatelessWidget { const TourPage({super.key});

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Museum tour')), body: SafeArea( child: ListView( padding: const EdgeInsets.all(16), children: [ for (final stop in tourStops.entries) TextButton( onPressed: () { Navigator.push( context, MaterialPageRoute<void>( builder: (_) => StopPage( title: stop.key, guide: stop.value, ), ), ); }, child: Row( children: [ Expanded(child: Text(stop.key)), const SizedBox(width: 12), const Icon(Icons.chevron_right, size: 24), ], ), ), ], ), ), ); } }

class StopPage extends StatelessWidget { const StopPage({ super.key, required this.title, required this.guide, });

final String title; final String guide;

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Tour stop'), leading: BackButton( onPressed: () => Navigator.pop(context), ), ), body: SafeArea( child: ListView( padding: const EdgeInsets.all(16), children: [ Text(title, style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 12), Text(guide), ], ), ), ); } }

The entire stop row is a button, so the visitor can tap the title as well as the arrow. The detail screen puts the full artwork title in the scrollable body. A long title can take several lines there without crowding the Back button in the top bar.

Both pages can be StatelessWidgets. The selected stop reaches the detail page through its constructor, and the navigator owns the route history. Neither page needs a separate variable to remember which screen should be visible.

Why does a scrolling list sometimes get an “unbounded height” error?

A scrolling list needs two measurements: the height of the visible window and the length of the content the visitor can scroll through. A museum tour might contain 40 stops even though only six fit on screen. The content can extend beyond the display, while the window still needs a finite height.

In the example, the ListView receives that height from the screen body. Now imagine adding a permanent instruction above it, such as “Choose a stop”. If you put the instruction and an ordinary ListView inside a Column, the column can offer the list an unbounded height during layout. The list then has no finite window to fill.

If the column itself has a bounded height, use Expanded(child: ListView(...)) for the list. The instruction takes the height it needs, and the list gets what remains. If the instruction should scroll away with the stops, put it inside the same list instead. Choose the structure by deciding what visitors should still see when they reach stop 40. Flutter’s constraint guide explains why putting a vertically expanding child inside another vertical scroll area creates a different problem.

What changes on a tablet or when a visitor opens a QR link?

A wider window changes the layout decision. A tablet might have enough space to keep the tour list on the left and show the selected artwork on the right. The same tablet in split-screen mode might need the single-column layout again. A LayoutBuilder lets a component inspect the width offered by its parent. Choose the switch point using a real title at a larger text size, with enough space left for the guide to be comfortable to read.

A QR code changes the navigation decision. A visitor scanning a label beside an artwork expects to arrive at that stop directly. They may never have opened the list. For that requirement, give each artwork a stable identifier and map a link such as /tour/stops/12 to its detail screen. Plan what “All stops” does when the detail page is the visitor’s first destination. Flutter recommends a router such as go_router for products that need direct links or synchronisation with the browser address bar. Its navigation and routing guide covers that step beyond the two-screen example.

How can you check whether the experience works?

  • Try the longest title first. Increase the phone’s text size. The full title should wrap, the arrow should remain visible, and the whole row should still open the correct stop.
  • Test Back from the middle of a long tour. Use enough stops to scroll, open one halfway down, then return. The visitor should recognise the same place in the list and be able to continue with the next artwork.
  • Take a different way in. If the product supports QR links, open one with the app closed. Check both the artwork that appears and the route a first-time visitor can take to the rest of the tour.

As Technical Lead at Apps Panel / Nomeo, I worked on a museum visitor app for a contemporary art foundation in the Paris area. The project included guided tours, multimedia content and indoor navigation. The code above is a teaching example. What connects it to that work is the visitor’s situation: someone standing in front of an artwork needs to recognise the right stop, read it comfortably, and find their place in the tour again.

If you are planning a mobile MVP, bring one journey people will take in more than one way, such as opening an item from a list or arriving through a shared link. I can help turn those entry points and return paths into a screen flow you can test on a phone. Explore my mobile app design and development expertise.