Contents

Home › Articles

Flutter Basic Widgets: A Practical Introduction

By Priya Shah · Published · 5 min read

Colorful building blocks arranged on a table representing basic UI widgets.
Colorful building blocks arranged on a table representing basic UI widgets. · Foto: analogicus / Pixabay

Flutter's UI is built entirely from widgets—small, immutable descriptions of part of the screen. Once you understand a handful of basic widgets, you can compose them into almost any layout. This guide covers the widgets you'll use daily, with practical advice on sizing, spacing, and keeping your widget tree shallow.

We'll focus on the widgets that appear in nearly every screen: Container, Row, Column, Text, Image, and ListView. For each, you'll see how it behaves, when to reach for it, and common mistakes that cost you layout time or frame rate. By the end, you'll know how to assemble these pieces into a responsive screen without guessing.

Container, Padding, and the Box Model

Container is the Swiss Army knife of Flutter layout: it combines padding, margin, decoration, and constraints. A common beginner mistake is wrapping everything in a Container when a simple Padding or SizedBox would do. Each extra widget adds a layer to the tree, and deep trees can slow down layout passes. Use Container when you need a background, border, or rounded corners; otherwise prefer the lighter widgets.

Sizing behavior trips people up. A Container with no child and no width/height expands to fill its parent if constraints allow. If you give it a child, it sizes to the child plus padding. To avoid surprises, set explicit constraints or wrap it in an Align or Center. In practice, most screens use Containers for cards with a BoxDecoration and 12–16 logical pixels of padding—enough to feel comfortable on phones.

When you need spacing between widgets, reach for SizedBox(height: 8) or Padding instead of Container(margin: ...). It's cheaper and clearer. Also, avoid nesting more than two or three Containers; if you find yourself deep in containers, consider a single decorated Container with Padding and child widgets.

  • Use Container for decoration and background, not for simple spacing.
  • Set width/height or constraints to avoid unexpected expansion.
  • Prefer SizedBox for fixed gaps; it's lighter than a full Container.

Row and Column: The Workhorses of Layout

Row and Column arrange children horizontally and vertically. They're flexible but have one rule: children must have bounded sizes along the main axis. If you put an unconstrained Text inside a Row without Flexible or Expanded, you'll get an overflow error on narrow screens. The fix is to wrap the text in Expanded or set a max width with ConstrainedBox.

MainAxisAlignment controls distribution along the main axis (start, center, spaceBetween, etc.), while CrossAxisAlignment aligns children on the cross axis. For a typical card with an icon and two lines of text, use a Row with CrossAxisAlignment.center and wrap the text column in Expanded. Add 8–12 logical pixels of spacing between elements with SizedBox or padding to keep the design breathable.

Nesting Rows inside Columns is normal, but keep an eye on depth. A screen with more than 10–12 nested layout widgets becomes hard to read and can affect performance during animations. Break complex sections into small stateless widgets—this also makes rebuilds cheaper because only the changed subtree updates.

1660 fps budget8120 fps budget12Image decode (20003Image decode (400p2Simple list item b
Typical frame time budget for smooth scrolling (ms) (ms)

Text and Image: Content Widgets

Text is straightforward but has a few gotchas. Use TextOverflow.ellipsis and maxLines to prevent overflow in tight spaces. For consistent typography, define a TextStyle once and reuse it, or use Theme.of(context).textTheme. Font sizes between 14 and 16 logical pixels work well for body copy on phones; headings often sit at 20–24. Avoid hardcoding colors that clash with dark mode—pull from the theme.

Image is where performance matters. Network images should use cached_network_image or at least set cacheWidth/cacheHeight to decode at display size. Loading a 2000-pixel-wide image into a 100-pixel thumbnail wastes memory and can cause jank. For local assets, provide 2x and 3x variants so Flutter picks the right resolution. Use BoxFit.cover for avatars and thumbnails, and always give images a size or aspect ratio to avoid layout shifts.

  • Set maxLines and overflow on Text to avoid overflow errors.
  • Decode network images at display size with cacheWidth/cacheHeight.
  • Provide multiple asset resolutions for crisp images on all screens.

ListView and Scrolling Basics

ListView is the go-to for scrollable lists. For small, fixed lists, ListView(children: [...]) is fine. For long or dynamic lists, use ListView.builder so children are built lazily. This keeps memory low and scroll smooth. A common mistake is putting a ListView inside a Column without giving it a bounded height; that throws an unbounded height error. Wrap it in Expanded or give it a SizedBox height.

Item extent matters. If all items have the same height, set itemExtent to help the scroll physics and layout. For variable heights, consider ListView.separated to add dividers without extra widgets. Keep item widgets lightweight: avoid heavy image decoding or complex layout in build. If you're coming from Android, the same principles apply as sizing a RecyclerView adapter for smooth lists; see How to Size a RecyclerView Adapter for Smooth Lists for numbers that translate well.

For grids, use GridView with SliverGridDelegateWithFixedCrossAxisCount. On phones, 2 columns for cards and 3–4 for thumbnails usually look right. Always test on a small device (320–360 logical pixels wide) to catch overflow early.

Composing Widgets into Screens

Real screens combine these basics: a Scaffold with an AppBar, a body containing a Column with a header, a ListView, and maybe a bottom button. The key is to break the UI into small widgets—each with a single responsibility. A common pattern is to create a stateless widget for each list item, which also helps Flutter rebuild only what changed. If you're unsure whether a widget should be stateless or stateful, the rule of thumb is: start stateless and add state only when you need to react to user input or animation.

Spacing and alignment should be consistent. Use a constant like 16 for screen padding and 8 for gaps between related elements. This makes the UI feel intentional. When you need platform-adaptive styling, consider Cupertino vs Material widgets; the choice affects navigation bars, buttons, and transitions. For a deeper comparison, see Cupertino vs Material Widgets: Which Style Fits Your App?.

Finally, test with real content. Placeholder text hides overflow issues. Use long strings and large font scales (up to 1.3x) to ensure your layout holds. A few minutes of testing saves hours of bug reports.

Performance and Maintenance Habits

Widgets are cheap, but rebuilds aren't free. Keep build methods pure and avoid creating new objects (like TextStyle or BoxDecoration) inside build when they don't change. Use const constructors where possible—Flutter can skip rebuilding const widgets entirely. For animations, drive them with AnimationController and be mindful of rebuild scope; a common pitfall is rebuilding the whole screen for a small animation. For timing guidance, see Flutter Animation Controllers Explained With Timing Numbers.

Profile your app in profile mode, not debug. Debug builds are much slower and can show jank that won't exist in release. Use the Flutter DevTools performance overlay to spot expensive frames; aim for under 16 ms per frame to hit 60 fps, or under 8 ms for 120 Hz devices. If you see consistent spikes, check for large images or deep widget trees in list items.

Keep your widget tree shallow and your code readable. Extract repeated patterns into custom widgets, and name them clearly. This pays off as your app grows and more developers join.

Common Flutter widgets and when to use them
WidgetPrimary useSizing behaviorPerformance note
ContainerDecoration, padding, backgroundExpands to fill if unconstrained; otherwise sizes to childHeavier than Padding/SizedBox; avoid deep nesting
PaddingAdd space around a childSizes to child plus paddingLightweight; preferred for spacing
Row / ColumnHorizontal/vertical layoutChildren must be bounded on main axisUse Expanded/Flexible to avoid overflow
TextDisplay textSizes to text; can overflow if unboundedSet maxLines and overflow for safety
ImageDisplay imagesNeeds explicit size or aspect ratioDecode at display size; use cacheWidth/cacheHeight
ListViewScrollable listNeeds bounded height in parentUse .builder for long lists; set itemExtent if fixed
  • Master Container, Row, Column, Text, Image, and ListView—they cover most screens.
  • Use Expanded/Flexible in Rows and Columns to prevent overflow on small devices.
  • Decode images at display size and prefer ListView.builder for long lists.
  • Keep widget trees shallow and extract small stateless widgets for readability and performance.
Priya Shah · Android and Kotlin author
Covers Kotlin, Jetpack libraries and Android architecture with a hands-on approach. Focuses on migration guides, database work and networking patterns for small teams.

Related articles

↑