flutter-errors
Flutter Errors Skill
This skill provides solutions for the most common Flutter runtime and layout errors.
RenderFlex Overflowed
Error: A RenderFlex overflowed by X pixels on the right/bottom.
Cause: A Row or Column contains children that are wider/taller than the available space.
Fix: Wrap the overflowing child in Flexible or Expanded, or constrain its size:
Row(
children: [
Expanded(child: Text('Long text that might overflow')),
Icon(Icons.info),
],
)
Vertical Viewport Given Unbounded Height
Error: Vertical viewport was given unbounded height.
Cause: A ListView (or other scrollable) is placed inside a Column without a bounded height.
Fix: Wrap the ListView in Expanded or give it a fixed height with SizedBox:
Column(
children: [
Text('Header'),
Expanded(
child: ListView(children: [...]),
),
],
)
InputDecorator Cannot Have Unbounded Width
Error: An InputDecorator...cannot have an unbounded width.
Cause: A TextField or similar widget is placed in a context without width constraints.
Fix: Wrap it in Expanded, SizedBox, or any parent that provides width constraints:
Row(
children: [
Expanded(child: TextField()),
],
)
setState Called During Build
Error: setState() or markNeedsBuild() called during build.
Cause: setState or showDialog is called directly inside the build method.
Fix: Trigger state changes in response to user actions, or defer to after the frame using addPostFrameCallback:
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
// Safe to call setState or showDialog here
});
}
ScrollController Attached to Multiple Scroll Views
Error: The ScrollController is attached to multiple scroll views.
Cause: A single ScrollController instance is shared across more than one scrollable widget simultaneously.
Fix: Ensure each scrollable widget has its own dedicated ScrollController instance.
RenderBox Was Not Laid Out
Error: RenderBox was not laid out: ...
Cause: A widget is missing or has unbounded constraints — commonly ListView or Column without proper size constraints.
Fix: Review your widget tree for missing constraints. Common patterns:
- Wrap
ListViewinExpandedinside aColumn. - Give widgets an explicit
widthorheightviaSizedBoxorConstrainedBox.
Debugging Layout Issues
- Use the Flutter Inspector (in DevTools) to visualize widget constraints.
- Enable "Show guidelines" to see layout boundaries.
- Add
debugPaintSizeEnabled = true;temporarily in yourmain()to paint layout bounds. - Refer to the Flutter constraints documentation for a deeper understanding of how constraints propagate.
References
More from evanca/flutter-ai-rules
riverpod
Uses Riverpod for state management in Flutter/Dart. Use when setting up providers, combining requests, managing state disposal, passing arguments, performing side effects, testing providers, or applying Riverpod best practices.
28bloc
Implement Flutter state management using the bloc and flutter_bloc libraries. Use when creating a new Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider in widgets, writing bloc unit tests, refactoring state management, or deciding between Cubit and Bloc.
21effective-dart
Apply Effective Dart guidelines to write idiomatic, high-quality Dart and Flutter code. Use when writing new Dart code, reviewing pull requests for style compliance, refactoring naming conventions, adding doc comments, structuring imports, enforcing type annotations, or running code review checks against Effective Dart standards.
20flutter-app-architecture
Implement layered Flutter app architecture with MVVM, repositories, services, and dependency injection. Use when scaffolding a new Flutter project, refactoring an existing app into layers, creating view models and repositories, configuring dependency injection, implementing unidirectional data flow, or adding a domain layer for complex business logic.
18testing
Write, review, and improve Flutter and Dart tests including unit tests, widget tests, and golden tests. Use when writing new tests, reviewing test quality, fixing flaky tests, adding test coverage, structuring test files, or choosing between unit and widget tests.
16architecture-feature-first
Structure Flutter apps using layered architecture (UI / Logic / Data) with feature-first file organization. Use when creating new features, designing the project folder structure, adding repositories, services, view models (or cubits/providers/notifiers), wiring dependency injection, or deciding which layer owns a piece of logic. State management agnostic.
16