Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the problem
With libraries connecting Flutter to the platform, there will be opportunities to occasionally write the path of a platform's resources or assets in Flutter and pass them to the platform side through a library or other means.
For example, the flutter_local_notifications icon:
https://pub.dev/packages/flutter_local_notifications#custom-notification-icons-and-sounds
For this level of frequency, the method of specifying a string is not a problem.
However, if you include an implementation that uses the Play Asset Delivery or On-Demand Resources features, the amount of assets will be quite large.
Actually, there are only a few libraries that can manipulate Play Asset Delivery and On-Demand Resources, and they are either old or underdeveloped.
So, I created a sample app to try it out, and I was able to create something that could be called with a common relative path.
https://github.com/yamashita-room-335/online_assets
So it occurred to me that if this flutter_gen had the ability to output iOS asset paths, Android asset paths, etc., it could create great synergy.
Not that this issue would be for my app, but to generate paths that could be passed to any official methods in the platform's code that specify paths as strings.
This may lead to the creation of new libraries that utilize platform-side assets and the development of functionality!
Describe the solution
Specify iOS assets (ios/Runner/Assets.xcassets) and Android asset packs (android/[asset_pack_name]), and get info from there, the asset path, On-Demand Resources Tags and Asset Pack Name, etc. would be great!
Example)
-
android/install_time_sample_pack/src/main/assets/install_time_sample_pack/dog_image.png
(The reason I have a folder with the pack name under the assets folder is to prevent name conflicts.) -
ios/Runner/Assets.xcassets/install_time_sample_pack/dog_image.imageset/dog_image.png
(It may be necessary for flutter_gen to check if Provides Namespace is enabled and build the path.)
# pubspec.yaml
# ...
flutter_gen:
android:
assets:
- android/install_time_sample_pack
- android/fast_follow_sample_pack
- android/on_demand_sample_pack
ios:
assets:
- ios/Runner/Assets.xcassets
// .dart
// old style
Image.platform(
packName: 'install_time_sample_pack',
relativePath: 'install_time_sample_pack/dog_image.png'
}
// flutter_gen style in Android
Image.platform(
packName: AndroidAssets.installTimeSamplePack.packName,
relativePath: AndroidAssets.installTimeSamplePack.dogImage.path
// .packName -> 'install_time_sample_pack'
// .path -> 'install_time_sample_pack/dog_image.png'
}
// flutter_gen style in iOS
Image.platform(
packName: IOSAssets.installTimeSamplePack.tag,
relativePath: IOSAssets.installTimeSamplePack.dogImage.nameWithExtension
// .tag -> 'install_time_sample_pack'
// .nameWithExtension -> 'install_time_sample_pack/dog_image.png'
// .name -> 'install_time_sample_pack/dog_image'
// .ext-> '.png' (Like the path library, an extension with a period would be good)
}
// If add more functionality, we might provide it in a merged class if the relative paths are the same on each platform and the file contents are the same.
Image.platform(
packName: PlatformAssets.installTimeSamplePack.packName,
relativePath: PlatformAssets.installTimeSamplePack.dogImage.path
// .packName -> 'install_time_sample_pack'
// .path -> 'install_time_sample_pack/dog_image.png'
}
Additional context
I think it would be fine to use the platform side's other assets generation tools and generate the Flutter code from that file.
This would likely reduce development costs.
I could not find any libraries for automatic asset generation in Android.
This was probably due to low demand for the Res folder, as it automatically generates R classes.
Code of Conduct
- I agree to follow this project's Code of Conduct