Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to add assets to debug build only?

Tags:

flutter

In Flutter, is there a way to add assets for debug builds only? Or to strip them from release builds?

The idea is to generate the play- and app-store screenshots from inside the app. Those screenshots are composed of various images that are otherwise unused and hence shouldn't be included in the release build. Question is, can those assets somehow be removed from release builds?

As an alternative, would it be possible to load the images from the Flutter project directory while the app is running in debug mode? -or at the emulator?

Could the test folder, perhaps, be abused for it?

How would you approach that requirement?

Any advise is welcome, Thank you.

like image 400
SePröbläm Avatar asked Sep 07 '25 06:09

SePröbläm


1 Answers

You can define a flavor for the build, and have assets defined for the flavor. From the docs:

flutter:
  assets:
    - assets/common/
    - path: assets/free/
      flavors:
        - free
    - path: assets/premium/
      flavors:
        - premium

The flavor is specified by passing --flavor <name> as an argument to flutter build.

like image 166
user2233706 Avatar answered Sep 09 '25 05:09

user2233706