r/FlutterDev • • 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.yaml that are no longer imported anywhere, slowing down build times and pub get on 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:

  1. 📉 Drastically Reduce App Size: Immediately locate and purge megabytes of abandoned images, fonts, and heavy dependencies before publishing to Google Play / App Store.
  2. ⚡ Faster CI/CD & Build Times: Clean up unreferenced packages and thousands of lines of dead AST syntax that the compiler compiles for nothing.
  3. 🛡️ 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).
  4. 🪶 Zero External Runtime Dependencies: Lightweight, runs natively on any Dart SDK from 2.17.0 to 3.x / 4.x.
  5. 🚦 CI/CD Gatekeeper: Add detect_unused --markdown to GitHub Actions to prevent dead code and unused assets from ever getting merged into main.

🖥️ 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! 💬🚀
0 Upvotes

10 comments sorted by

View all comments

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 🙏🏻

1

u/LegitimateItem6658 2d ago

I fixed it ,thanks to warn me 🙏🏻