Flutter has two fundamental widget types: StatelessWidget (immutable, no internal state that changes) and StatefulWidget (can hold and update mutable state, rebuilding when state changes). Choosing the right one is fundamental to building Flutter UIs.
StatelessWidget — no changing state
// a StatelessWidget: just describes UI based on its inputs (immutable, no internal state)
class Greeting extends StatelessWidget {
final String name;
const Greeting(this.name);
@override
Widget build(BuildContext context) {
return Text('Hello, $name'); // UI depends only on inputs, never changes itself
}
}
// → use for UI that doesn't change on its own (static content, displays based on inputs)
