Skip to the workspace
Pebellslearn by building
Widgets  ›  Lesson

Stateless Widgets

Stateless Widgets 12 minA stateless widget is an immutable description of part of the screen whose build method depends only on its constructor arguments and inherited context.

flutter / Stateless Widgets

Explore each scene at your own pace.

01 · The rule

The rule

Stateless Widgets

Sprout's home screen is a list of plants, each row showing a name and "water in 2 days". Every row looks the same apart from its data. In Flutter, that row is a widget: a small, reusable description of part of the screen.

The rule

A stateless widget turns its inputs into a picture, nothing more.

class PlantTile extends StatelessWidget {
  const PlantTile({super.key, required this.name, required this.daysLeft});

  final String name;
  final int daysLeft;

  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: const Icon(Icons.local_florist),
      title: Text(name),
      subtitle: Text('Water in $daysLeft days'),
    );
  }
}
  • The fields are final. A widget is an immutable description; it never edits itself.
  • The const constructor lets Flutter reuse identical instances, such as const Icon(...), instead of rebuilding them.
  • build returns more widgets. ListTile, Icon and Text are widgets too, so the screen is a tree of widgets inside widgets.
  • super.key passes an optional key to the parent class. Keys help Flutter tell apart items of the same type, for example when a list is reordered.

To show a different plant, the parent simply creates another PlantTile with other arguments: PlantTile(name: 'Cactus', daysLeft: 12).

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.