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.
flutter pub run build_runner build
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
Assets.google.image() //=> Image.assets("assets/google.png")
To continuously watch the changes to assets folder, type the following command.
flutter pub run build_runner watch --delete-conflicting-outputs
— delete-conflicting-outputs flag lets you solve any issues regarding outputs of previous build.