Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: package_parameter_enabled is ignored for AssetGenImage "provider" method #360

Closed
2 tasks done
orevial opened this issue Feb 16, 2023 · 4 comments · Fixed by #361
Closed
2 tasks done

[BUG]: package_parameter_enabled is ignored for AssetGenImage "provider" method #360

orevial opened this issue Feb 16, 2023 · 4 comments · Fixed by #361
Assignees
Labels
bug Something isn't working
Milestone

Comments

@orevial
Copy link
Contributor

orevial commented Feb 16, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Version

5.2.0

Command type

build_runner (Default)

What happened?

When generating image assets this package generates an AssetGenImage class that is the base class for all images and that provides two methods:

  • image, that provides a Flutter Image.asset
  • provider, that provides an ImageProvider

Also the package accepts an additional output parameter named package_parameter_enabled that allow us to take profit for a packaged architecture assets generation as explained in Flutter official assets doc.

This works great for image method because its implementation use keyName getter as the asset name, which contains the full package path.

However for some reason provider uses _assetName as its asset name, which does not contain the asset full path with the package.

Also the provider implementation should probably propose a complete method with all the parameters from Flutter original AssetImage constructor.

The solution is really easy, I could propose a PR for it.

Relevant a pubspec.yaml.

name: myapp
description: A new Flutter package project.
version: 1.0.0
publish_to: none

environment:
  sdk: '>=2.19.0 <3.0.0'
  flutter: ">=3.7.0 <4.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.5
  flutter_svg: ^1.1.6

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^2.3.0
  flutter_gen_runner: ^5.1.0+1

flutter_gen:
  integrations:
    flutter_svg: true
  output: lib/assets/gen
  assets:
    enabled: true
    outputs:
      # Assets need to be referenced with the package option, see
      # https://docs.flutter.dev/development/ui/assets-and-images#from-packages
      package_parameter_enabled: true

flutter:
  uses-material-design: true
  assets:
    - assets/images/logo/

Relevant log output

Example of generated `AssetGenImage`:


class AssetGenImage {
  const AssetGenImage(this._assetName);

  final String _assetName;

  Image image({
    Key? key,
    AssetBundle? bundle,
    ImageFrameBuilder? frameBuilder,
    ImageErrorWidgetBuilder? errorBuilder,
    String? semanticLabel,
    bool excludeFromSemantics = false,
    double? scale,
    double? width,
    double? height,
    Color? color,
    Animation<double>? opacity,
    BlendMode? colorBlendMode,
    BoxFit? fit,
    AlignmentGeometry alignment = Alignment.center,
    ImageRepeat repeat = ImageRepeat.noRepeat,
    Rect? centerSlice,
    bool matchTextDirection = false,
    bool gaplessPlayback = false,
    bool isAntiAlias = false,
    String? package = 'screens',
    FilterQuality filterQuality = FilterQuality.low,
    int? cacheWidth,
    int? cacheHeight,
  }) {
    return Image.asset(
      _assetName,
      key: key,
      bundle: bundle,
      frameBuilder: frameBuilder,
      errorBuilder: errorBuilder,
      semanticLabel: semanticLabel,
      excludeFromSemantics: excludeFromSemantics,
      scale: scale,
      width: width,
      height: height,
      color: color,
      opacity: opacity,
      colorBlendMode: colorBlendMode,
      fit: fit,
      alignment: alignment,
      repeat: repeat,
      centerSlice: centerSlice,
      matchTextDirection: matchTextDirection,
      gaplessPlayback: gaplessPlayback,
      isAntiAlias: isAntiAlias,
      package: package,
      filterQuality: filterQuality,
      cacheWidth: cacheWidth,
      cacheHeight: cacheHeight,
    );
  }

  ImageProvider provider() => AssetImage(_assetName);

  String get path => _assetName;

  String get keyName => 'packages/screens/$_assetName';
}

Code of Conduct

  • I agree to follow this project's Code of Conduct
@orevial orevial added the bug Something isn't working label Feb 16, 2023
@wasabeef wasabeef self-assigned this Feb 21, 2023
@wasabeef
Copy link
Member

@orevial
Thank you for your reporting.

The solution is really easy, I could propose a PR for it.

Could you?

@orevial
Copy link
Contributor Author

orevial commented Feb 22, 2023

@wasabeef here you go 🙂

Note that I didn't update the changelogs, I didn't know if I had to do it and how to use melos to do it

@saulrmzlpz
Copy link

Waiting for this change... 😄

@blaugold
Copy link
Contributor

@wasabeef Is there anything I can do to help land the mentioned PR?

wasabeef added a commit that referenced this issue Apr 17, 2023
Closes #360

Co-authored-by: Olivier Revial <olivier.revial@steeple.com>
Co-authored-by: Daichi Furiya <dadadada.chop@gmail.com>
@wasabeef wasabeef added this to the 5.3.0 milestone Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants