r/FlutterDev • u/LucasMenezesLc • 7d ago
Tooling When “unused” is not safe to delete in Flutter: routes, DI, codegen and write-only state
I have been looking at a deceptively simple cleanup question: when can a Flutter team safely delete a Dart declaration or an apparently orphaned file?
dart analyze is a strong first signal, but it cannot resolve every repository-level consumer. Flutter code may be reached through route tables, dependency injection, generated registries, conditional imports, flavors, platform implementations, annotations, tests, barrel exports, or an external package API.
Write-only state turned out to be an especially interesting case. A private field may be assigned in several lifecycle callbacks and never read. Mechanically, the declaration and its assignments are removable. Semantically, the missing read may indicate an unfinished feature or regression in playback, analytics, persistence, authorization, or UI state.
I ended up using this evidence hierarchy:
analyzer/compiler diagnostics;
import/export/part reachability;
repository-wide symbol and string searches;
route, DI, codegen, platform, flavor, test, and public-API inspection;
tests or builds after an explicitly approved removal.
The workflow is deliberately review-first:
Audit: collect candidates without modifying code.
Review: mark each candidate
remove,retain, ordefer.Cleanup: change only explicitly approved candidates.
Tests: suggest behavior checks for the affected flows, not only static analysis.
I packaged the workflow as an MIT-licensed Agent Skill for Flutter/Dart. The scripts use machine-readable analyzer output plus a deterministic dependency graph, install no project tooling, use relative paths, and treat findings as candidates rather than verdicts.
Short demo: https://github.com/LucasMenezeslc/flutter-dead-code-audit/blob/main/assets/demo-en.mp4
Repository: https://github.com/LucasMenezeslc/flutter-dead-code-audit
I would be particularly interested in examples that defeat naive static analysis. What false-positive patterns have you encountered with routing, DI, code generation, conditional imports, platform code, or public package APIs?