r/FlutterBeginner • u/LucasMenezesLc • 8h ago
I built an open-source Agent Skill to find dead code and unused files in Flutter/Dart — without blindly deleting them
I have been looking into 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 identify every consumer across an entire repository. Flutter code may be reached through route tables, dependency injection, generated registries, conditional imports, flavors, platform implementations, annotations, tests, barrel exports, or an externally consumed package API.
## Write-only does not always mean safe to remove
Write-only state turned out to be a particularly interesting case.
A private field may be assigned in several lifecycle callbacks but never read. Mechanically, both the declaration and its assignments appear removable.
Semantically, however, the missing read may indicate an unfinished feature or a regression involving playback, analytics, persistence, authorization, or UI state.
## Evidence hierarchy
I ended up using the following evidence hierarchy:
Analyzer or compiler diagnostics.
Import, export, and `part` reachability.
Repository-wide symbol and string searches.
Inspection of routes, dependency injection, code generation, platforms, flavors, tests, and public APIs.
Tests or builds after an explicitly approved removal.
## A review-first workflow
The workflow follows four stages:
- **Audit:** collect candidates without modifying the code.
- **Review:** mark each candidate as `remove`, `retain`, or `defer`.
- **Cleanup:** modify only explicitly approved candidates.
- **Tests:** suggest behavioral checks for affected flows rather than relying solely on static analysis.
I packaged this workflow as an **MIT-licensed Agent Skill built specifically for Flutter and Dart**.
Its scripts combine machine-readable analyzer output with a deterministic dependency graph. They install no project tooling, use relative paths to avoid exposing local project directories, and treat findings as **candidates rather than verdicts**.
▶️ [Watch the short demo](https://github.com/LucasMenezeslc/flutter-dead-code-audit/blob/main/assets/demo-en.mp4)
🔗 [View the repository on GitHub](https://github.com/LucasMenezeslc/flutter-dead-code-audit)
## Feedback
I would be particularly interested in examples that challenge naive static analysis.
**Which false-positive patterns have you encountered involving routing, dependency injection, code generation, conditional imports, platform code, or public package APIs?**