如何在 Android Studio 或 Visual Studio Code 中查找未使用的 Flutter 类 [英] How to find unused flutter classes in Android Studio or Visual Studio Code

查看:42
本文介绍了如何在 Android Studio 或 Visual Studio Code 中查找未使用的 Flutter 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于客户端对应用程序的需求变化很快,我有近 200 个 dart 文件,其中许多未使用.除了手动一一搜索之外,我还有什么方法可以找到未使用的类?在 Android Studio 中,我可以使用检查代码"功能找到未使用的 java 或 kotlin 类.但是我找不到任何用于 dart/flutter 的相同目的的工具.

Because rapid change in app requirement from client, I have nearly 200 dart files, and many of them are unused. Is there any way for me to find unused classes except resorting to manually search one by one? In Android Studio, I can find java or kotlin classes which are unused by using "inspect code" feature. But I can't find any tools for the same purpose for dart / flutter.

提前感谢您的帮助.

推荐答案

Dart 代码指标 https://pub.dev/packages/dart_code_metrics支持为 Flutter 查找未使用的文件.

Dart code metrics https://pub.dev/packages/dart_code_metrics supports finding unused files for flutter.

安装:

      flutter pub add --dev dart_code_metrics

运行flutter package get";或使用您的 IDE 来发布获取".

run "flutter packages get" or use your IDE to "Pub get".

运行:

     flutter pub run dart_code_metrics:metrics check-unused-files lib

结果:

    Unused file: lib/generated_plugin_registrant.dart
    Unused file: lib/ux/Pdf/makepdfdocument.dart
    Unused file: lib/ux/RealEstate/realestatetable.dart
...
Total unused files - 11

如何找到未使用的 dart 或 flutter 文件(中)

dart-code-metrics 简介(中)

代码度量还可以提供以下方面的洞察:

Code-metrics can also give insight in:

  • 圈复杂度
  • 代码行
  • 最大嵌套
  • 方法数量
  • 参数数量
  • 源代码行
  • 类的权重

这篇关于如何在 Android Studio 或 Visual Studio Code 中查找未使用的 Flutter 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆