FlutterGen / flutter_gen

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
https://pub.dev/packages/flutter_gen
MIT License
1.46k stars 146 forks source link

Is ImageProvider no longer supported? #235

Closed IvanYue closed 2 years ago

IvanYue commented 2 years ago

flutter_gen_runner: ^4.1.6 image

lcdsmao commented 2 years ago

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

kolotum commented 2 years ago

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');
lcdsmao commented 2 years ago

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.

kolotum commented 2 years ago

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 commented 2 years ago

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?

erleizh commented 2 years ago

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

dokkaebi commented 2 years ago

What is the best way to create a DecorationImage now?

anandsubbu007 commented 2 years ago

any update?