Flutter comes with tree shaking compilation. Including only the code used.
But this is easily breakable inadvertently.
Is there any way to test and debug tree shaking?
Tree Shaking is also used in Flutter to reduce the final packet size. Flutter provides three construction modes. For each mode, the Flutter compiler has different optimizations on the output binary files. The Tree Shaking mechanism can't be triggered in the Debug mode.
kDebugMode top-level constant Null safety bool const kDebugMode. A constant that is true if the application was compiled in debug mode. More specifically, this is a constant that is true if the application was not compiled with '-Ddart. vm.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With