flutter_gen
flutter_gen copied to clipboard
Is ImageProvider no longer supported?
flutter_gen_runner: ^4.1.6

@IvanYue
Is ImageProvider no longer supported
Yes.
Can you try Assets.images.icon.allInOne.image(width: ...) or Image.asset(Assets.images.icons.allInOne.path, width: ...)?
I like the new way introduced in 4.2:
Assets.images.icon.allInOne.image(
width: Get.width,
height: 267.h,
fit: BoxFit.fill,
)
But I am not sure if path works when package_parameter_enabled: true is set.
Also right now we require the inheritance of AssetImage, because we can use ImageProvider in several places, e.g. to preload images.
I think we can still use the new image() method and re-add AssetImage inheritance like:
class AssetGenImage extends AssetImage {
const AssetGenImage(String assetName) : super(assetName, package: 'my_flutter_package');
But I am not sure if path works when package_parameter_enabled: true is set.
It works. Please see here: https://github.com/FlutterGen/flutter_gen/blob/05e307b298316c2b93634902e520b435ed2e1db5/example/lib/main.dart#L43
We change to Image.asset constructor because it supports more optional parameters.
Also right now we require the inheritance of AssetImage, because we can use ImageProvider in several places, e.g. to preload images.
You can still get provider via Assets.images.allInOne.image(...).image.
This ImageProvider should be a more correct one, which respect the optional parameters, than the previous inheritance one.
But I am not sure if path works when package_parameter_enabled: true is set.
It works. Please see here:
https://github.com/FlutterGen/flutter_gen/blob/05e307b298316c2b93634902e520b435ed2e1db5/example/lib/main.dart#L43
Just to clarify: My expectation was that we can use path to fully address the image source. Using the code from example:
Assets.images.chip1.image(), // works
Image.asset(Assets.images.chip1.path), // works
// Use from example_resource package.
res.Assets.images.flutter3.image(), // works
Image.asset(res.Assets.images.flutter3.path), // unable to load, requires packages parameter
Image.asset(res.Assets.images.flutter3.path, package: 'example_resources'), // works
res.Assets.images.flutter3.path only works with Image.asset when we set the package parameter.
You can still get provider via
Assets.images.allInOne.image(...).image. ThisImageProvidershould be a more correct one, which respect the optional parameters, than the previous inheritance one.
Thank you for pointing this option out. Do we have any performance impacts when we create an Image widget for each asset we want to preload/precache?
need ImageProvider provider() => AssetImage(_assetName);
What is the best way to create a DecorationImage now?
any update?