A different way to use assets in Flutter

In this blog, I’ll show you a new way to use assets in Flutter.

How this new new approach look like?

How to implement this?

Add the following dependencies first in dev_dependencies in pubspec.yaml.

Add your required assets in assets folder and mention it in pubspec.yaml.

This is how I added

After that run the following command in command prompt/Terminal.

This command generates a new file in lib folder i.e. lib/gen/assets.gen.dart

Now you can use the assets in your project as below

To continuously watch the changes to assets folder, type the following command.

— delete-conflicting-outputs flag lets you solve any issues regarding outputs of previous build.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store