Skip to main content

Mobile development · Beginner · 24 min

Build Flutter screens from widgets, rows, columns and lists

By Padding · Updated 26 Nov 2026
Ubuntu 26.04 · Flutter 3.50.1 · Dart 3.14.0

You will build a clinic services screen in Flutter 3.50 from rows, columns and a lazy list, make taps update it with setState, theme it with Material 3 and prove it works at phone size with a widget test.

On this page

Every Flutter screen is a tree of small widgets, and most screens are built from the same handful: a Scaffold for the page, an AppBar, Column and Row to arrange things, Padding and SizedBox for space, Expanded to share out width or height, and a ListView for anything that scrolls. Once you can combine those, you can build most of what you see in real apps.

This tutorial starts where installing Flutter and running your first app stops. You build one screen for a clinic: a list of 16 services, each showing an icon, a name, a short description and how long it takes. Tapping a service selects it, and a summary bar at the top shows how many are selected and the total time. One service has a long Swahili name, so you can see how a row copes with text much longer than the English names around it, which matters for any app used in more than one language.

You write the code in four small files, check each one with flutter analyze, and finish with a widget test that sets the screen to the width of a small Android phone, taps services and proves the list only builds the rows it needs.

Step 1 · Create the project

Check that the SDK on your PATH is Flutter 3.50:

Bash
flutter --version

The first line should start with Flutter 3.50.1 (or a later 3.50 release) on the stable channel, and the Dart line should say 3.14. If it shows an older version, run flutter upgrade.

Create a project with only the Android and iOS wrappers, since this is a phone app. The project lives in a practice folder that the last step deletes:

Bash
mkdir -p ~/flutter-screens-demo
cd ~/flutter-screens-demo
flutter create --platforms=android,ios clinic_services
cd clinic_services
rm test/widget_test.dart

The starter test checks the counter app that flutter create writes, and you are about to replace that app, so it goes now. You write your own test in step 6.

Check it worked

Bash
cd ~/flutter-screens-demo/clinic_services
ls lib
flutter analyze

lib holds only main.dart, and flutter analyze ends with No issues found!. The analyser uses the rules in analysis_options.yaml, which flutter create points at the flutter_lints package.

Step 2 · Describe the services with const constructors

Start with the data, so the widgets have something to show. A clinic service is a small class whose fields never change after it is made. Mark every field final and give the class a const constructor:

Bash
cd ~/flutter-screens-demo/clinic_services
cat > lib/services.dart <<'DART'
import 'package:material_ui/material_ui.dart';

class ClinicService {
  const ClinicService({
    required this.id,
    required this.name,
    required this.description,
    required this.minutes,
    required this.icon,
  });

  final String id;
  final String name;
  final String description;
  final int minutes;
  final IconData icon;
}

const clinicServices = <ClinicService>[
  ClinicService(
    id: 'gp',
    name: 'GP consultation',
    description: 'See a doctor about a new or ongoing problem.',
    minutes: 15,
    icon: Icons.medical_services,
  ),
  ClinicService(
    id: 'bp',
    name: 'Blood pressure check',
    description: 'A nurse measures and records your blood pressure.',
    minutes: 10,
    icon: Icons.favorite,
  ),
  ClinicService(
    id: 'antenatal-nutrition',
    name: 'Ushauri wa lishe kwa akina mama wajawazito',
    description: 'Antenatal nutrition advice, given in Swahili.',
    minutes: 30,
    icon: Icons.pregnant_woman,
  ),
  ClinicService(
    id: 'malaria',
    name: 'Malaria rapid test',
    description: 'A finger-prick test with a result in about 20 minutes.',
    minutes: 15,
    icon: Icons.bloodtype,
  ),
  ClinicService(
    id: 'bloods',
    name: 'Blood tests',
    description: 'Samples taken for tests your doctor has asked for.',
    minutes: 10,
    icon: Icons.science,
  ),
  ClinicService(
    id: 'child-vaccines',
    name: 'Childhood vaccinations',
    description: 'Routine vaccines for babies and young children.',
    minutes: 20,
    icon: Icons.vaccines,
  ),
  ClinicService(
    id: 'eyes',
    name: 'Eye test',
    description: 'Checks your sight and the health of your eyes.',
    minutes: 30,
    icon: Icons.visibility,
  ),
  ClinicService(
    id: 'hearing',
    name: 'Hearing check',
    description: 'A short test in a quiet room with headphones.',
    minutes: 20,
    icon: Icons.hearing,
  ),
  ClinicService(
    id: 'dental',
    name: 'Dental check-up',
    description: 'A dentist examines your teeth and gums.',
    minutes: 30,
    icon: Icons.healing,
  ),
  ClinicService(
    id: 'therapy',
    name: 'Talking therapy',
    description: 'A first session with a counsellor.',
    minutes: 50,
    icon: Icons.psychology,
  ),
  ClinicService(
    id: 'baby-clinic',
    name: 'Baby clinic',
    description: 'Weight, growth and feeding checks for babies.',
    minutes: 20,
    icon: Icons.child_care,
  ),
  ClinicService(
    id: 'prescriptions',
    name: 'Prescription review',
    description: 'A pharmacist goes through the medicines you take.',
    minutes: 15,
    icon: Icons.local_pharmacy,
  ),
  ClinicService(
    id: 'diabetes',
    name: 'Diabetes review',
    description: 'Blood sugar, feet and medicine checks.',
    minutes: 30,
    icon: Icons.medication,
  ),
  ClinicService(
    id: 'over-65',
    name: 'Over-65 health check',
    description: 'A longer appointment covering several checks at once.',
    minutes: 40,
    icon: Icons.elderly,
  ),
  ClinicService(
    id: 'family-planning',
    name: 'Family planning',
    description: 'Contraception advice and supplies.',
    minutes: 20,
    icon: Icons.health_and_safety,
  ),
  ClinicService(
    id: 'travel-vaccines',
    name: 'Travel vaccines',
    description: 'Vaccines and advice before you travel abroad.',
    minutes: 30,
    icon: Icons.flight,
  ),
];
DART

The file imports package:material_ui/material_ui.dart, which is where the Material widgets, Colors and Icons live from Flutter 3.47 on. flutter create already lists material_ui in pubspec.yaml, and the older package:flutter/material.dart import still works but the analyser flags it as deprecated.

A const constructor lets Dart build an object while it compiles your program instead of while it runs. Two const expressions with the same values give you the very same object in memory, not two equal copies. Because the list is declared const, every ClinicService inside it is constant too, so you write const once at the front rather than on each entry. The same idea pays off in widgets: you will see const Text(...) and const SizedBox(...) throughout this tutorial, and step 5 explains why Flutter can skip work for them.

Check it worked

Bash
cd ~/flutter-screens-demo/clinic_services
flutter analyze lib/services.dart

The analyser reports No issues found!. If you remove final from a field, the constructor can no longer be const and the analyser reports an error on it, which is a quick way to see the rule in action. Put final back before you continue.

Step 3 · Build one row with Padding, Row, Column and Expanded

Each service is shown by one row widget. It is a StatelessWidget: everything it shows comes from the values passed to it, and it keeps nothing of its own. When the service or its selected state changes, the parent builds a new ServiceTile with new values.

Bash
cd ~/flutter-screens-demo/clinic_services
cat > lib/service_tile.dart <<'DART'
import 'package:clinic_services/services.dart';
import 'package:material_ui/material_ui.dart';

class ServiceTile extends StatelessWidget {
  const ServiceTile({
    super.key,
    required this.service,
    required this.selected,
    required this.onTap,
  });

  final ClinicService service;
  final bool selected;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    final colours = Theme.of(context).colorScheme;
    final text = Theme.of(context).textTheme;

    return Semantics(
      button: true,
      selected: selected,
      child: InkWell(
        onTap: onTap,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
          child: Row(
            children: [
              CircleAvatar(
                backgroundColor: colours.primaryContainer,
                foregroundColor: colours.onPrimaryContainer,
                child: Icon(service.icon),
              ),
              const SizedBox(width: 12),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      service.name,
                      style: text.titleMedium,
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                    ),
                    Text(
                      service.description,
                      style: text.bodyMedium?.copyWith(
                        color: colours.onSurfaceVariant,
                      ),
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ],
                ),
              ),
              const SizedBox(width: 12),
              Text('${service.minutes} min', style: text.labelLarge),
              const SizedBox(width: 8),
              Icon(
                selected ? Icons.check_circle : Icons.radio_button_unchecked,
                color: selected ? colours.primary : colours.outline,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
DART

Read the tree from the outside in. Semantics tells screen readers such as TalkBack that the row is a button and whether it is selected, since a tick icon on its own says nothing to someone who cannot see it. InkWell makes the whole row tappable and draws the Material ripple. Padding adds space inside the row. Row places its children side by side, and the Column inside it stacks the name above the description, with crossAxisAlignment: CrossAxisAlignment.start lining both up on the left instead of centring them.

Diagram of one service row: Padding around a Row holding an icon, a gap, an Expanded Column with the name and description, a gap, the duration text and a tick icon. Arrows show the icon at 40 wide, the duration as wide as its text, and Expanded taking all the width that is left
Expanded is what lets a long name wrap instead of breaking the row.

The important widget is Expanded. Flutter lays out by passing limits down the tree and sizes back up: a parent tells each child the smallest and largest size it may be, the child picks a size within those limits, and the parent then places it. A Row first lays out its children that are not flexible, here the icon, the gaps, the duration and the tick, and lets each take the width it wants. Whatever width is left goes to the Expanded children. That gives the Column, and the two Text widgets inside it, a fixed width, so a long name wraps onto a second line and then ends with an ellipsis.

Without Expanded, the name's Text would ask for the full width of its words on one line. On a narrow phone with the Swahili name, the row would run out of space, and Flutter would draw a yellow and black striped bar on the right edge and print A RenderFlex overflowed by ... pixels in the console.

Check it worked

Bash
cd ~/flutter-screens-demo/clinic_services
flutter analyze lib

The analyser ends with No issues found!. If it warns about sort_child_properties_last, a child: argument has moved above another argument; the flutter_lints rules ask for child and children to come last so the tree reads top to bottom.

Step 4 · Put the screen together with Scaffold and ListView.builder

Now arrange a whole screen. Start with a version that cannot select anything yet, so the layout is all you have to think about:

Bash
cd ~/flutter-screens-demo/clinic_services
cat > lib/services_screen.dart <<'DART'
import 'package:clinic_services/service_tile.dart';
import 'package:clinic_services/services.dart';
import 'package:material_ui/material_ui.dart';

class ServicesScreen extends StatelessWidget {
  const ServicesScreen({super.key, required this.services});

  final List<ClinicService> services;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Clinic services')),
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(16),
            child: Row(
              children: [
                Expanded(
                  child: Text(
                    '${services.length} services',
                    style: Theme.of(context).textTheme.titleSmall,
                  ),
                ),
                const FilledButton(onPressed: null, child: Text('Continue')),
              ],
            ),
          ),
          const Divider(height: 1),
          Expanded(
            child: ListView.builder(
              itemCount: services.length,
              itemBuilder: (context, index) {
                return ServiceTile(
                  service: services[index],
                  selected: false,
                  onTap: () {},
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
DART

Then replace lib/main.dart. The app widget sets up Material 3 colours from one seed colour and opens the services screen:

Bash
cd ~/flutter-screens-demo/clinic_services
cat > lib/main.dart <<'DART'
import 'package:clinic_services/services.dart';
import 'package:clinic_services/services_screen.dart';
import 'package:material_ui/material_ui.dart';

void main() {
  runApp(const ClinicApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Clinic services',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.teal),
      ),
      darkTheme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: Colors.teal,
          brightness: Brightness.dark,
        ),
      ),
      home: const ServicesScreen(services: clinicServices),
    );
  }
}
DART

Scaffold is the page: it places the AppBar at the top and the body below it, and later hosts the snack bar. The body is a Column of three children: the summary row, a one-pixel Divider, and the list.

Diagram of the services screen on a phone: an AppBar titled Clinic services, a summary row reading 1 selected · 15 min with a Continue button, a divider and a list of service rows. A legend shows that rows on screen and a few below it are built, and later rows are not built yet
Scaffold, then a Column whose last child is an Expanded list.

ListView.builder does not build all 16 rows up front. It calls itemBuilder only for the rows that are on screen, plus a small margin past the bottom edge (the cache extent) so the next rows are ready when you scroll. With 16 rows that hardly matters; with 1,600, it is the difference between a screen that opens at once and one that stalls, especially on a low-cost Android phone with little memory. Use ListView.builder whenever the number of rows comes from data.

The list sits inside Expanded for a reason. A Column lets its children be as tall as they like, and a list would like to be infinitely tall, so on its own it fails with Vertical viewport was given unbounded height. Expanded hands the list exactly the height the Column has left after the summary and the divider, and the list scrolls inside that.

ColorScheme.fromSeed builds a full Material 3 palette (primary, containers, surfaces, outlines) from one colour, in a light and a dark version. Material 3 has been Flutter's default since 3.16, so there is no flag to turn on. The tile already uses those colours by name, primaryContainer for the icon circle and outline for an unselected tick, so changing the seed recolours the whole screen.

Start the app on any device that flutter devices lists, and leave it running:

Bash
cd ~/flutter-screens-demo/clinic_services
flutter run

Check it worked

Bash
cd ~/flutter-screens-demo/clinic_services
flutter analyze

The analyser ends with No issues found!. On the device you see an app bar titled "Clinic services" on a pale, slightly tinted background (Material 3 takes it from the colour scheme's surface, not the seed colour), "16 services" with a greyed-out Continue button, and a list you can scroll to "Travel vaccines". The Swahili name wraps onto two lines without a striped overflow bar. Change Colors.teal to Colors.deepOrange, save, press r in the terminal running the app, and the icon circles turn pale orange while the unselected ticks and the app bar's faint tint shift towards orange too. Change it back.

Step 5 · Make a tap change the screen with setState

Selections belong to the screen, not to any one row, and they change while the screen is open. Data like that needs a StatefulWidget. The widget itself stays immutable; it creates a separate State object that Flutter keeps alive between builds, and the selections live there. Replace the screen:

Bash
cd ~/flutter-screens-demo/clinic_services
cat > lib/services_screen.dart <<'DART'
import 'package:clinic_services/service_tile.dart';
import 'package:clinic_services/services.dart';
import 'package:material_ui/material_ui.dart';

class ServicesScreen extends StatefulWidget {
  const ServicesScreen({super.key, required this.services});

  final List<ClinicService> services;

  @override
  State<ServicesScreen> createState() => _ServicesScreenState();
}

class _ServicesScreenState extends State<ServicesScreen> {
  final Set<String> _selected = {};

  void _toggle(String id) {
    setState(() {
      if (!_selected.remove(id)) {
        _selected.add(id);
      }
    });
  }

  void _continue() {
    final count = _selected.length;
    final noun = count == 1 ? 'service' : 'services';
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text('$count $noun ready to book')),
    );
  }

  @override
  Widget build(BuildContext context) {
    final minutes = widget.services
        .where((service) => _selected.contains(service.id))
        .fold(0, (total, service) => total + service.minutes);

    return Scaffold(
      appBar: AppBar(title: const Text('Clinic services')),
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(16),
            child: Row(
              children: [
                Expanded(
                  child: Text(
                    '${_selected.length} selected · $minutes min',
                    style: Theme.of(context).textTheme.titleSmall,
                  ),
                ),
                FilledButton(
                  onPressed: _selected.isEmpty ? null : _continue,
                  child: const Text('Continue'),
                ),
              ],
            ),
          ),
          const Divider(height: 1),
          Expanded(
            child: ListView.builder(
              itemCount: widget.services.length,
              itemBuilder: (context, index) {
                final service = widget.services[index];
                return ServiceTile(
                  service: service,
                  selected: _selected.contains(service.id),
                  onTap: () => _toggle(service.id),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
DART

The state class reads the widget's values through widget, as in widget.services. _toggle changes the set inside setState, which marks the screen as needing a new frame, so Flutter calls build again. That build works out the new total, enables Continue once something is selected (a null onPressed is how a Flutter button is disabled), and passes selected: true to the tapped row. Change state only inside setState; changing _selected without it updates the data but leaves the screen as it was.

Diagram of three trees side by side. The widget tree holds ServicesScreen, ServiceTile and Icon, new objects on every build. The element tree holds a StatefulElement with its State and StatelessElements, kept if type and key match. The render tree holds RenderFlex for the Column and Row and RenderParagraph for text, where only changed parts repaint
Widgets are throwaway descriptions. Elements and render objects stay.

Calling build again sounds expensive, but widgets are only lightweight descriptions. Behind them Flutter keeps two longer-lived trees. The element tree records what is actually mounted on screen, and it is where your State object lives, which is why the selections survive every rebuild. The render tree does the real work of sizing, positioning and painting; Row and Column both become a RenderFlex, and each Text becomes a RenderParagraph.

After setState, Flutter walks the new widgets against the existing elements. Where the widget type (and key, if there is one) matches, it keeps the element and its render object and only updates the properties that changed, so the tick icon is repainted and the rest of the row is left alone. A const widget is the very same object on every build, so its element can see straight away that nothing changed and skip that part of the tree entirely. That is why const on widgets such as const Text('Continue') and const Divider(height: 1) is worth the habit.

The app moved from a stateless to a stateful screen, so in the terminal running it press R for a hot restart rather than r. A hot restart rebuilds the app from scratch, which is the safe choice after turning a class from stateless into stateful.

Check it worked

Bash
cd ~/flutter-screens-demo/clinic_services
flutter analyze

The analyser ends with No issues found!. On the device, tap "GP consultation": its tick fills, the summary reads 1 selected · 15 min and Continue turns teal. Tap "Blood pressure check" and the summary reads 2 selected · 25 min. Tap Continue and a snack bar says 2 services ready to book. Tap a selected row again to clear it.

Step 6 · Test the screen at phone size

A widget test runs your widgets on a simulated screen with no device or emulator, which makes it fast enough to run on every change. The default test screen is 800 by 600 logical pixels, wider than most phones, so the test first sets it to 320 by 640, the size of a small budget Android phone, where the long Swahili name has the least room:

Bash
cd ~/flutter-screens-demo/clinic_services
cat > test/services_screen_test.dart <<'DART'
import 'package:clinic_services/main.dart';
import 'package:clinic_services/services.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';

void useSmallPhone(WidgetTester tester) {
  tester.view.physicalSize = const Size(960, 1920);
  tester.view.devicePixelRatio = 3;
  addTearDown(tester.view.reset);
}

void main() {
  testWidgets('selecting services updates the summary', (tester) async {
    useSmallPhone(tester);
    await tester.pumpWidget(const ClinicApp());

    expect(find.text('Clinic services'), findsOneWidget);
    expect(find.byType(ListView), findsOneWidget);
    expect(
      find.text('Ushauri wa lishe kwa akina mama wajawazito'),
      findsOneWidget,
    );
    expect(tester.takeException(), isNull);
    expect(find.text('0 selected · 0 min'), findsOneWidget);

    final button = find.widgetWithText(FilledButton, 'Continue');
    expect(tester.widget<FilledButton>(button).onPressed, isNull);

    await tester.tap(find.text('GP consultation'));
    await tester.pump();
    expect(find.text('1 selected · 15 min'), findsOneWidget);
    expect(tester.widget<FilledButton>(button).onPressed, isNotNull);

    await tester.tap(find.text('Blood pressure check'));
    await tester.pump();
    expect(find.text('2 selected · 25 min'), findsOneWidget);

    await tester.tap(find.text('GP consultation'));
    await tester.pump();
    expect(find.text('1 selected · 10 min'), findsOneWidget);

    await tester.tap(button);
    await tester.pump();
    expect(find.text('1 service ready to book'), findsOneWidget);
  });

  testWidgets('the list builds rows only as they scroll in', (tester) async {
    useSmallPhone(tester);
    await tester.pumpWidget(const ClinicApp());

    final last = clinicServices.last;
    expect(find.text(last.name, skipOffstage: false), findsNothing);

    await tester.scrollUntilVisible(find.text(last.name), 200);
    await tester.ensureVisible(find.text(last.name));
    await tester.pumpAndSettle();

    await tester.tap(find.text(last.name));
    await tester.pump();
    expect(find.text('1 selected · ${last.minutes} min'), findsOneWidget);
  });
}
DART
flutter test

tester.view sets the simulated screen in physical pixels, so 960 by 1920 at a pixel ratio of 3 is 320 by 640 logical pixels, and addTearDown puts it back after the test. pumpWidget builds the app once, tap sends a tap to the middle of the widget a finder found, and pump builds the next frame, so the test sees what setState changed. takeException returns any error raised during layout, which is where a RenderFlex overflowed error from a row that does not fit would show up.

The second test proves the list is lazy. find.text normally ignores widgets that are built but off screen; with skipOffstage: false it finds every widget that exists. "Travel vaccines" is not found at all at first, because ListView.builder has not built that row yet. scrollUntilVisible drags the list 200 pixels at a time until the row appears, and ensureVisible brings it fully into view so the tap lands on it.

Check it worked

flutter test ends with All tests passed! and shows +2, one for each test. In the first test, change '2 selected · 25 min' to '2 selected · 30 min', run flutter test again, and it fails with an error that names the text it could not find. Change it back and run the tests and the analyser once more:

Bash
cd ~/flutter-screens-demo/clinic_services
flutter test
flutter analyze

Both pass: All tests passed! and No issues found!.

Step 7 · Get ready for small, low-cost Android phones

Plenty of your users, in Lagos, Nairobi or anywhere else, may be on an entry-level Android phone with a small screen, limited memory and prepaid data. The screen you built already does the important things for them: rows are built lazily, constant widgets are skipped on rebuild, and long names wrap instead of breaking the layout, which the test checks at 320 pixels wide. Two more habits help.

First, keep checking at a large text size. Many people raise the system font size, and translations into languages such as Swahili, Hausa or French often run longer than English. With the app running, open the phone's display settings, set the largest font size, and look at the rows again: names should wrap to two lines and end with an ellipsis, never overflow.

Second, keep downloads small. A single Android APK contains machine code for every processor type. When you hand out an APK directly rather than through Google Play, which delivers the right part for each phone itself, build one file per processor type:

Bash
cd ~/flutter-screens-demo/clinic_services
flutter build apk --split-per-abi

This needs the Android SDK from Android Studio. It writes separate files under build/app/outputs/flutter-apk/, such as app-arm64-v8a-release.apk and app-armeabi-v7a-release.apk, and each is noticeably smaller than one combined APK. Most current phones need the arm64-v8a file; older and very cheap ones may need armeabi-v7a.

Check it worked

With the largest system font size set, every service name is still readable and no row shows the yellow and black striped bar. If you ran the build, ls build/app/outputs/flutter-apk/ lists one APK per processor type.

Step 8 · Clean up

When you have finished, put the phone's font size back to how you like it, and stop the app with q in its terminal. The next command deletes the practice project and everything in it; skip it if you want to keep experimenting with the project:

Bash
cd ~
rm -rf ~/flutter-screens-demo

Check it worked

ls ~/flutter-screens-demo reports that there is no such file or directory. The Flutter SDK in ~/develop/flutter is untouched.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.