首页 > 解决方案 > 如何在 Flutter 中测试/调试摇树?

问题描述

Flutter 自带 tree-shaking 编译。仅包括使用的代码。

但这很容易在不经意间破坏。

有什么方法可以测试和调试摇树?

标签: dartflutter

解决方案


For debugging, it is possible to connect to the Observatory in profile mode. Then inspect the content of desired dart file

You won't see the actual sources in profile mode; but you'll see an overview of what is inside the file, including the defined classes and their methods.

For example, a widget such a the following:

class Home extends StatelessWidget {
  _unused() {
    print('home');
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

when inspected in the Observatory in profile mode; _unused method will not be in the function list:

enter image description here


推荐阅读