Skip to content

Lesson 2 of 9 · 24m

How Flutter Actually Renders: Widgets, Elements, and Frames

Learn the widget-element-render object split, build scheduling, and the frame budget that determines whether the interface feels native.

Flutter's superpower is also its first trap: it draws the interface itself. You are not configuring platform buttons; you are describing a scene that Flutter owns end to end. Once you understand the widget tree, element tree, render tree, and frame pipeline, most "Flutter is weird" behavior becomes mechanical.

Widgets are descriptions, not objects on screen

Widgets are immutable configuration. They are cheap to create and destroy. The framework compares them and updates longer-lived elements and render objects:

class StatusBadge extends StatelessWidget {
  const StatusBadge({required this.label, required this.tone, super.key});

  final String label;
  final BadgeTone tone;

  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
      decoration: BoxDecoration(color: tone.background),
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
        child: Text(label, style: Theme.of(context).textTheme.labelSmall),
      ),
    );
  }
}

The build method can run often. It should be fast, predictable, and free of side effects. Do not start network requests in build; use lifecycle methods, controllers, or state objects that understand when work should happen.

Keys preserve identity when order changes

The element tree matches widgets by type, position, and key. If you reorder stateful items without keys, Flutter can reuse the wrong state. Symptoms look supernatural: a checkbox jumps rows, a text field keeps someone else's text, or an animation controller survives the item it belonged to.

for (final task in tasks)
  TaskTile(key: ValueKey(task.id), task: task)

Use stable object IDs, not list indexes, when rows can move. Random keys are just as bad: they force destruction and re-creation every build.

The frame budget is brutally small

At 60 Hz you have about 16.7 milliseconds per frame; on a 120 Hz device, closer to 8.3. A frame includes input, build, layout, paint, compositing, and platform work. Flutter DevTools labels expensive work clearly, but the rough mental model is:

input/event -> build dirty widgets -> layout -> paint -> rasterize/composite -> present

Rebuilding a large branch is not automatically fatal, but rebuilding it repeatedly with layout invalidation is. const constructors, selective rebuild boundaries, cached expensive objects, and stable keys all reduce avoidable work.

Constraints go down, sizes go up

Layout failures become obvious when you repeat the rule: constraints go down, sizes go up, parents position children. A Container does not magically center or size itself; it behaves according to parent constraints and child behavior. Expanded only has meaning inside a Flex such as Row or Column. An unbounded height error means some parent asked a child to choose a size without limits, and the child had no finite answer.

Field notes

  • The first frame can include shader compilation jank on some platforms; test cold start, not only hot reload.
  • setState marks an element dirty; it does not immediately rebuild synchronously.
  • Expensive build output wrapped in RepaintBoundary may reduce repaint cost, but too many boundaries can increase memory and compositing work.
  • Avoid MediaQuery.of(context) when only one property is needed; use MediaQuery.sizeOf(context) and friends to reduce rebuild scope.
  • If a widget behaves like the wrong row after sorting, inspect keys before blaming animation or networking.

Was this lesson helpful?

Sign in to rate