Flutter Concepts Explained — Detailed Breakdown

This page explains in detail the main Flutter concepts: StatelessWidget vs StatefulWidget, MaterialApp, Scaffold, and setState(). For each topic, you'll find explanations of what they are, their sub-concepts or related components, and references for further reading.

1. StatelessWidget vs StatefulWidget

StatelessWidget: A widget that describes part of the UI by building a constellation of other widgets that describe the UI more concretely. It does not maintain any mutable state. The widget's appearance only depends on the configuration information it is given.

Key points about StatelessWidget:

StatefulWidget:

A widget that has mutable state. This means the UI can change dynamically over time based on user interaction or asynchronous events.

Key points about StatefulWidget:

Other related concepts:

Official Flutter docs: Managing state

2. MaterialApp

MaterialApp is a convenience widget that wraps several widgets commonly required for a Material Design app.

Main responsibilities:

Key properties you should know:

Related concepts and widgets:

Official Flutter docs: MaterialApp

3. Scaffold

The Scaffold widget provides a basic visual layout structure for a Material Design app.

Main features of Scaffold:

Why use Scaffold?

It saves you from manually implementing the standard visual layout structure of apps, like app bars, drawers, snack bars, and floating buttons, with consistent Material Design look and feel.

Related widgets:

Official Flutter docs: Scaffold

4. setState()

setState() is a method used inside the State class of a StatefulWidget.

Purpose:

It notifies Flutter that the internal state of the widget has changed in a way that might impact the UI. Flutter then schedules a rebuild of the widget subtree.

How to use it:

void increment() {
  setState(() {
    count++;
  });
}

Important notes:

Flutter docs: Using setState()