Description
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 FlutterImage.asset
provider
, that provides anImageProvider
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