Flutter Core Concepts
Layout
Flutter UI is constraint-driven. Understanding the parent-to-child layout contract is essential to avoid overflow, jitter, and brittle composition.
Widget Taxonomy
Every visual element, padding wrapper, and layout rule in Flutter is a widget. Choosing the right widget type keeps state localized and prevents unnecessary subtree rebuilds.
Stateless vs Stateful
Use StatelessWidget when a component depends only on configuration passed through its constructor. Reach for StatefulWidget when the widget owns mutable state—such as animation controllers, text input, or local toggles—that changes over time via setState.
class CounterLabel extends StatelessWidget {
const CounterLabel({super.key, required this.value});
final int value;
@override
Widget build(BuildContext context) => Text('Count: $value');
}
class CounterButton extends StatefulWidget {
const CounterButton({super.key});
@override
State<CounterButton> createState() => _CounterButtonState();
}
Composition
Prefer many focused widgets over giant build methods. Smaller widgets improve readability, testability, and rebuild isolation.
Constraints
Flutter lays out the widget tree in a single pass. Understanding how constraints flow downward and sizes flow upward explains almost every layout error you will encounter.
Constraint Flow
Every render box negotiates its geometry with its parent in three steps:
- Parent sends min/max constraints to child.
- Child chooses size inside constraints.
- Parent positions child.
Responsive Example
When a layout must adapt between narrow mobile screens and wide desktop viewports, LayoutBuilder exposes the parent's exact box constraints so you can branch cleanly without hardcoding device types:
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final isWide = constraints.maxWidth >= 900;
return isWide
? Row(children: [Expanded(child: Sidebar()), Expanded(flex: 3, child: Content())])
: Column(children: [Header(), Expanded(child: Content())]);
},
);
}
Theming
A consistent visual system starts with a centralized theme rather than inline colors and font sizes on individual widgets.
ThemeData
Define your color palette and typography once in ThemeData at the root MaterialApp, then read values via Theme.of(context) throughout your screens:
final appTheme = ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF1565C0)),
useMaterial3: true,
textTheme: Typography.blackMountainView,
);
Tokens
Centralize spacing, color, and typography constants. Avoid scattering hardcoded visual values across feature widgets.
Rendering
Smooth 60/120 fps UI depends on keeping build() methods fast and limiting how much of the widget tree invalidates on each state change.
Rebuilds
Follow these practices to keep frame times predictable:
- Use const constructors for static subtrees.
- Extract dynamic nodes to isolate rebuild scope.
- Use profiler timeline before introducing micro-optimizations.
Engineering Notes
Create a shared UI architecture guide: widget naming conventions, layout standards, and theme extension rules.
Common Mistakes
Most layout exceptions and maintenance bottlenecks trace back to three habits:
- Using nested Rows/Columns without understanding constraint propagation.
- Hardcoding paddings and colors per screen.
- Building entire pages in one widget class, making refactors risky.
Practice Scope
Build a responsive dashboard screen with reusable widgets, centralized theme tokens, and two adaptive breakpoints.
Back to roadmap: Flutter Roadmap