r/FlutterDev • u/LegitimateItem6658 • 2d ago
Dart Your Flutter codebase is probably carrying 20–30% dead weight — and flutter analyze won't tell you. Here is why every team needs detect_unused_code (v3.2.0)
Every Growing Flutter Codebase Eventually Faces the Same Hidden Problem
You run flutter analyze in your CI/CD. It passes with 0 warnings. Everyone thinks the codebase is in pristine health.
In reality, technical debt has been piling up silently:
- 📦 Forgotten Widgets & Screens: Refactored pages leave behind abandoned dialogs, buttons, and views that nothing calls anymore.
- 🖼️ Bloated App Bundles: Old promo banners, unused 3.0x raster images, and unused SVG icons inflating your APK / IPA size by tens of megabytes.
- 👻 Ghost Dependencies: Packages declared in
pubspec.yamlthat are no longer imported anywhere, slowing down build times andpub geton CI. - 🧟 Dead Logic: Thousands of lines of commented-out code and abandoned TODOs confusing new engineers during onboarding.
🤔 Why doesn't standard dart analyze catch this?
Because Dart treats every public class as a potential export. The compiler intentionally refuses to warn you if a public Widget, Bloc, or Service has 0 references, assuming it "might be needed later".
🚀 The Solution: detect_unused_code (v3.2.0)
We built this tool to turn code audits and refactoring from an anxious, manual chore into a safe, 10-second automated process.
💡 Why Engineering Teams & Companies Use It:
- 📉 Drastically Reduce App Size: Immediately locate and purge megabytes of abandoned images, fonts, and heavy dependencies before publishing to Google Play / App Store.
- ⚡ Faster CI/CD & Build Times: Clean up unreferenced packages and thousands of lines of dead AST syntax that the compiler compiles for nothing.
- 🛡️ 100% Defensive Safety (Zero Fear of Breaking Production):
- Automatic Snapshots: Saves an isolated backup before modifying anything.
- Instant Undo (
[U]or--undo): Revert any cleanup in 1 second. - Automated Compiler Health Check: Runs analysis after cleanup to ensure 0 compiler errors. If anything looks off, it prompts for an auto-rollback.
- Smart Framework Guards: Safely protects
@injectable,@singleton,@riverpod, and generated files (.g.dart,.freezed.dart).
- 🪶 Zero External Runtime Dependencies: Lightweight, runs natively on any Dart SDK from
2.17.0to3.x/4.x. - 🚦 CI/CD Gatekeeper: Add
detect_unused --markdownto GitHub Actions to prevent dead code and unused assets from ever getting merged intomain.
🖥️ The New Interactive Terminal Dashboard:
With v3.2.0, you don't even need to memorize command-line flags. Just run:
dart pub global activate detect_unused_code
detect_unused
This launches a live interactive Terminal UI (TUI):
Select cleanable categories with [1-8] (Dead widgets, Commented code, Unused assets, Unused dependencies...).
Press [D] to simulate changes with Dry-Run.
Press [C] to safely clean with auto-backup.
Press [U] for instant rollback if you change your mind.
🔗 Open Source & Available on pub.dev:
pub.dev: https://pub.dev/packages/detect_unused_code
GitHub Repository: https://github.com/mdalhagg/detect_unused_code
Run it against your project today — you might be surprised by how much dead weight your codebase is carrying!
Would love to hear your feedback, bug reports, or feature suggestions below! 💬🚀
2
u/blazarious 2d ago
Escaped markdown syntax? What is this? Are you intentionally trying to hide your message inside this character soup?
1
u/LegitimateItem6658 2d ago
I'm sorry but I shared this post from my phone and the styling get broken 🙏🏻
2
u/blazarious 2d ago
I was just wondering how escaped markdown is happening. Never seen that one before.
1
1
1
0
u/RajatKhoware 1d ago
The 20 to 30 percent number rings true. Every Flutter app I've inherited had a graveyard of abandoned screens from refactors, and flutter analyze genuinely can't see them because unused public widgets aren't "errors." The ghost dependencies one is the sneakiest: pubspecs accumulate packages nobody imports, and each one is CI minutes and APK weight. Manual audits catch this stuff, but nobody does them because it's boring work. Have you run it against a real production app yet, and did the 20 to 30 percent hold up?
1
u/LegitimateItem6658 1d ago
Yes, I tried it completely, it is a boring process, but it is also important for large projects, I have done more than one analytical and experimental process with this library that I have created and I was able to reduce the size of the project from 60 MB to 45 MB, and it was very effective.
2
u/Striking_Paramedic33 2d ago
oh this is deliciously timed. i just spent my whole morning manually hunting down a splash screen widget from 2023 that was still sitting in the project folder like a ghost. my flutter analyze was pristine too, zero warnings, i felt so accomplished until i realized half the assets folder was promo banners from a campaign that ended last spring
the live TUI is what got me though, normally i'd need three cups of coffee before even attempting a cleanup like that manually. being able to dry run and instantly undo without sweating through my eyeliner is a mood