Size Optimization Tips for Flutter App

Β· Β· 479 words Β· 3 minute read

1. Use SVG for icons and vector images πŸ”—

2. Use WEBP instead of JPG/PNG πŸ”—

It’s like JPG/PNG but it’s ~25% smaller in size

3. Shake Your Icons πŸ”—

Flutter has the functionality to shake out unused icons from Material, Cupertino, FontAwesome, etc. fonts.

For iOS πŸ”—

If you’re building from Xcode, you can set the TREE_SHAKE_ICONS environment variable

For Android πŸ”—

It would be setting the tree-shake-icons property in the

4. Whatever you use, COMPRESS it πŸ”—

Everybody knows they can and should JPG/PNG compress but how many people know you can also compress SVG and WEBP images?

5. Zip your animations, too πŸ”—

6. Use gzip to minimize everything πŸ”—

For example lang files

final String response = await rootBundle.loadString('assets/en_us.json');
List<int> original = utf8.encode(response);
List<int> compressed = gzip.encode(original);
List<int> decompress = gzip.decode(compressed);
final enUS = utf8.decode(decompress);

You can save sizes using gzip compression

7. Use Proguard Rules πŸ”—

Add to the file android/app/build.gradle

android {
  buildTypes {
    getByName("release") {
      // Enables code shrinking, obfuscation, and optimization
      minifyEnabled = true
      // Enables resource shrinking
      shrinkResources = true
      // Enables proguard rules

Add to the file android/app/

## Flutter wrapper
-keep class** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
-keep class** { *; } // uncomment this if you are using firebase in the project
-dontwarn io.flutter.embedding.**

8. Obfuscate Your Code πŸ”—

This function gives you both security and reducing size! here is how.

For Android πŸ”—

Add to the file /android/


For IOS πŸ”—

9. Use Google Fonts πŸ”—

This package will dynamically download fonts when only used. Not every variant of the font

10. Use Cache Image Network πŸ”—

It gives you cache images automatically and gives you some space

11. Enable more aggressive optimizations πŸ”—

Removes unused codes, combines classes to make smaller the code, etc.



12. Compress Native Libs πŸ”—

Reduce the download size and the size of the app on devices



13. Split debug info from your code πŸ”—

That splits debug info from our code and helps us create smaller apk

flutter build appbundle --split-debug-info=/<path-to-export>

14. Deferred Components πŸ”—

Flutter has the capability to build apps that can download additional Dart code and assets at runtime. This allows apps to reduce install APK size and download features and assets when needed by the user.

15. Detect heavy packages and get rid of them if possible πŸ”—

For Android’s AppBundle πŸ”—

flutter build appbundle --target-platform android-arm64 --analyze-size

For Android’s APK πŸ”—

flutter build apk --target-platform android-arm64 --analyze-size

For iOS πŸ”—

flutter build ios --analyze-size