flutter_gen icon indicating copy to clipboard operation
flutter_gen copied to clipboard

Is ImageProvider no longer supported?

Open IvanYue opened this issue 2 years ago • 8 comments

flutter_gen_runner: ^4.1.6 image

IvanYue avatar May 27 '22 11:05 IvanYue

@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: ...)?

lcdsmao avatar May 28 '22 14:05 lcdsmao

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');

kolotum avatar May 30 '22 22:05 kolotum

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.

lcdsmao avatar May 31 '22 00:05 lcdsmao

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.

kolotum avatar May 31 '22 22:05 kolotum

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.

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?

kolotum avatar May 31 '22 22:05 kolotum

need ImageProvider provider() => AssetImage(_assetName);

erleizh avatar Jun 06 '22 14:06 erleizh

What is the best way to create a DecorationImage now?

dokkaebi avatar Jun 15 '22 00:06 dokkaebi

any update?

anandsubbu007 avatar Sep 03 '22 08:09 anandsubbu007