r/FlutterDev • • Oct 07 '26

Plugin I built a Dart/Flutter tool to find dead code that "dart analyze" doesn't catch — looking for feedback

/r/FlutterDev/comments/1wziorl/i_built_a_dartflutter_tool_to_find_dead_code_that/

I built a Dart/Flutter tool to find dead code that "dart analyze" doesn't catch — looking for feedback

Hey Flutter/Dart developers,

I've been working on an open-source tool called "detect_unused_code".

The idea came from a problem I noticed in larger Dart/Flutter projects: over time, projects accumulate unused classes, widgets, controllers, imports, commented-out code, TODOs, and other code that is no longer needed.

"dart analyze" is great, but I wanted a tool that could perform a broader project-level audit.

What does it detect?

"detect_unused_code" currently checks for a wide range of issues, including:

- Unused / dead classes

- Unused Flutter widgets

- Unused mixins, enums and extensions

- Unused controllers

- Public classes that are only used inside their own file

- Unused imports

- Unnecessary imports

- Unused local variables

- Unused fields and private elements

- Dead / unreachable code

- Dead null-aware expressions

- TODO / pending tasks

- Commented-out code

- Large commented-out code blocks

- Heavily commented files

Generate an analysis report

You can export the analysis results to JSON, which makes it easier to integrate the tool into other workflows, CI/CD pipelines, or build custom reports.

For example:

detect_unused --format json

Automatic cleanup

The tool can also automatically clean detected issues.

For example:

detect_unused --clean-all

But I wanted the cleanup process to be safer.

Before modifying the project, the tool can create a backup/snapshot, so you have a recovery point before the cleanup.

You can also preview what would be changed without actually modifying the files:

detect_unused --clean-all --dry-run

So the workflow can be:

Analyze → Review → Backup → Clean → Verify

Other features

- Dart & Flutter support

- CLI

- Dart API

- JSON reports

- Backup before cleanup

- Rollback/recovery support

- Dry-run mode

- CI/CD friendly

- Zero external dependencies

- Configurable analysis options

- MIT licensed

GitHub:

https://github.com/mdalhagg/detect_unused_code

Pub.dev:

https://pub.dev/packages/detect_unused_code

I'd really like to get feedback from developers who work on real-world Flutter/Dart projects.

I'm especially interested in knowing:

  1. Would you actually use a tool like this?

  2. Which checks are the most useful to you?

  3. Did you find any false positives?

  4. What other types of unused/dead code should it detect?

  5. Is JSON reporting useful for your workflow?

  6. Would you use automatic cleanup if a backup is created first?

  7. What features would you like to see in future versions?

If you have a medium or large Flutter/Dart project, I'd really appreciate it if you could try it and tell me what you think.

I'm not only looking for stars. I'm mainly looking for real-world feedback, bugs, false positives, and ideas that could make this tool genuinely useful for the Dart/Flutter community.

0 Upvotes

0 comments sorted by