Home > Blockchain >  How do dependencies affect the overall size of the app?
How do dependencies affect the overall size of the app?

Time:10-25

Say that in my flutter app I depend on a very bulky package.

*** pubspec.yaml ***
dependencies:
   some_package: ^0.15.0

But from that package I only need a certain file.

*** main.dart ***
import 'package:some_package/some_file.dart';

After compilation, will the size of my app be affected by the overall size of the dependency package? Or just the file I chose to import?

CodePudding user response:

According to dart.dev documentation on the dart2js tool:

Tip: Don’t worry about the size of your app’s included libraries. The dart2js tool performs tree shaking to omit unused classes, functions, methods, and so on. Just import the libraries you need, and let dart2js get rid of what you don’t need.

So, with tree shaking dead code will be eliminated from the final package, but only in certain build modes. In debug build mode tree shaking will not be performed, according to this Flutter build modes explanation page. Other build modes (Release and profile) will have tree shaking to be performed.

So, in your case, if you declare a package and use only one of its classes, it should increase only the imported on the resulting app size. Be mindful that sometimes one file depends on multiple others.

You can read more about it in this github issue.

  • Related