flutter-bug-investigation
Bug Solving Skill (Flutter)
Foundation: Extends shared-bug-investigation with Flutter patterns.
Flutter Context
flutter --version && grep "sdk:" pubspec.yaml
grep -r "BlocProvider\|ChangeNotifier\|GetX" lib/ # State management
RCA: Check All Layers (data/domain/view)
# View Layer: Bloc/Cubit, widgets, state
find lib/feature/<feature>/view -name "*.dart"
# Domain Layer: Models, repository interfaces, business logic
find lib/feature/<feature>/domain -name "*.dart"
# Data Layer: DTOs, datasources, API calls
find lib/feature/<feature>/data -name "*.dart"
Debug by layer: View (Bloc emits?) → Domain (model mapping?) → Data (DTO parsing?)
Common Bug Patterns
Bloc State
// ❌ Missing emit → ✅ Add emit(LoadingState()), emit(LoadedState(data)), emit(ErrorState())
Null Safety
// ❌ user!.name → ✅ user?.name ?? 'Guest'
BuildContext After Async
// ❌ Navigator.pop(context) after await → ✅ if (!mounted) return; Navigator.pop(context);
GetIt DI
// ❌ Not registered → ✅ Add @injectable, run build_runner
Method Channels
// ❌ Wrong name → ✅ Match iOS/Android channel name
Widget Rebuilds
// ❌ BlocBuilder wraps Scaffold → ✅ Wrap only body
Memory Leaks
// ❌ Stream not closed → ✅ Override close(), call super.close()
Error Quick Reference
| Error | Fix |
|---|---|
type 'Null' is not a subtype |
Add ?? defaults |
Looking up deactivated widget |
Check mounted |
Object not registered |
Add @injectable, run build_runner |
MissingPluginException |
Implement native iOS/Android |
setState() after dispose() |
Cancel timers/streams |
RenderBox overflow |
Fix constraints |
Tools
flutter analyze # Must pass (0 errors)
flutter test # All tests
flutter run --profile # Performance
Validation
-
flutter analyze= 0 errors -
flutter testpasses - Manual test fixed
- Tested iOS + Android (if platform-specific)
More from desquared/agents-rules-skills
shared-bug-investigation
Scientific method expert for systematic bug investigation and root cause analysis. Use when users report bugs, crashes, unexpected behavior, or debugging requests. Applies hypothesis-driven investigation, controlled experiments, and rigorous validation across any programming language or platform.
23android-performance-profiler
Identifies potential performance bottlenecks in Jetpack Compose code including expensive recompositions, unnecessary redraws, and memory issues. Use when code involves lists, animations, complex UI, or when the user asks about performance optimization.
19ios-swiftui-architecture-review
Analyze SwiftUI view hierarchies and suggest MVVM or other architectural improvements. Use when **reviewing existing SwiftUI code**, creating new SwiftUI components, analyzing view structure, or when the user asks about SwiftUI architecture patterns. Best for code review and refactoring guidance.
13android-compose-architecture-review
Analyze Jetpack Compose UI hierarchies and suggest MVVM/MVI or other architectural improvements. Use when reviewing existing Compose code, creating new Compose components, analyzing composable structure, or when the user asks about Compose architecture patterns. Best for code review and refactoring guidance.
13android-accessibility-validator
Checks and suggests accessibility improvements for Jetpack Compose and Android Views including TalkBack labels, dynamic text support, and color contrast. Use when creating or modifying UI components, screens, or when the user asks about accessibility.
12android-kotlin-api-design-reviewer
Review function and class interfaces for Kotlin Coding Conventions compliance. Use when creating public APIs, reusable components, library interfaces, or when the user asks for API design review or Kotlin naming conventions.
11