kLayer2Content top-level constant
String
const kLayer2Content
Implementation
const String kLayer2Content = '''
=== LAYER 2: COMMUNITY ANTI-PATTERNS ===
Most common Flutter mistakes found across thousands of real production apps:
WIDGET TREE:
- Nesting over 15 levels in UI code → extract into named widget classes
- Container with single child and no decoration → use SizedBox or Padding
- Align inside Align → outer Align is always redundant, remove it
- GestureDetector wrapping InkWell → double gesture detection, use one or the other
- Scaffold inside Scaffold → causes visual glitches and nav issues
- Stack with single child → just use the child directly
STATE MANAGEMENT MISTAKES:
- Calling context.watch() inside a callback or initState → runtime error
- Using context.read() in build() → misses updates, use context.watch()
- Calling setState() on a disposed widget → crashes in debug, silent in release
- Creating a ChangeNotifier inside build() → new instance on every rebuild
- Not calling super.dispose() → memory leaks
- Storing BuildContext across async gaps → stale context crashes
PERFORMANCE KILLERS:
- print() statements in production → measurable performance hit, remove all
- Not disposing: TextEditingController, AnimationController, ScrollController,
FocusNode, StreamSubscription → memory leaks that grow over app lifetime
- Rebuilding entire screen on small state change → use Consumer or Selector
to limit rebuild scope to only the widget that needs to change
- Heavy widgets in initState synchronously → blocks first frame render
- Using GlobalKey excessively → expensive, causes full subtree rebuilds
CODE QUALITY:
- Files over 300 lines → split into smaller focused widgets
- Single build() method over 100 lines → impossible to maintain, extract widgets
- Magic numbers in UI (SizedBox(height: 24.0)) → use a spacing constants file
- Hardcoded strings in widgets → use localization or constants
- TODO comments older than 30 days → technical debt, address or remove
''';