I have few resources in my flutter package 'packme' which is used by multiple apps.
There are some resources(contains images and PDF files) which are required to be loaded within my packages and served to app in bytes. I am trying multiple ways to load data but not successful.
I have added file to packme/assets/images/test-image-01.png
as well packme/lib/assets/images/test-image-01.png
packme/pubspec.yaml:
flutter:
# To add assets to your package, add an assets section, like this:
assets:
- assets/images/
- lib/assets/images/
Having following function to test path exists or not, prints false for all:
void checkPaths() {
List<String> images = [
'packages/packme/assets/images/test-image-01.png',
'images/test-image-01.png',
'lib/assets/images/test-image-01.png',
];
for (var image in images) {
print(
"fileExists? $image ${File(image).existsSync()}"); //Prints false for each file
}
What is the way to load bytes data for file from assets
or lib
from a package?
I hev checked multiple posts and flutter-docs but it doesn't work.
Surprisingly
File('packages/packme/assets/images/test-image-01.png').existSync()
is givingfalse
but following code works fine:Can anyone reflect on this?