-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the AssetGenImage code to be another Intergration, so it l…
…ooks more similar to svg/lottie/etc. This simplifies the assets_generator, and no longer forces AssetGenImage to be output even when there are no images.
- Loading branch information
Showing
13 changed files
with
128 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
packages/core/lib/generators/integrations/image_integration.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import 'package:flutter_gen_core/generators/integrations/integration.dart'; | ||
import 'package:flutter_gen_core/settings/asset_type.dart'; | ||
|
||
class ImageIntegration extends Integration { | ||
ImageIntegration(String packageName) : super(packageName); | ||
|
||
String get packageParameter => isPackage ? ' = package' : ''; | ||
|
||
String get keyName => | ||
isPackage ? '_assetName' : "'packages/$packageName/\$_assetName'"; | ||
|
||
@override | ||
List<String> get requiredImports => ['package:flutter/widgets.dart']; | ||
|
||
@override | ||
String get classOutput => _classDefinition; | ||
|
||
String get _classDefinition => '''class AssetGenImage { | ||
const AssetGenImage(this._assetName); | ||
final String _assetName; | ||
${isPackage ? "\n static const String package = '$packageName';" : ''} | ||
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, | ||
${isPackage ? deprecationMessagePackage : ''} | ||
String? package$packageParameter, | ||
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({ | ||
AssetBundle? bundle, | ||
${isPackage ? deprecationMessagePackage : ''} | ||
String? package$packageParameter, | ||
}) { | ||
return AssetImage( | ||
_assetName, | ||
bundle: bundle, | ||
package: package, | ||
); | ||
} | ||
String get path => _assetName; | ||
String get keyName => $keyName; | ||
} | ||
'''; | ||
|
||
@override | ||
String get className => 'AssetGenImage'; | ||
|
||
@override | ||
String classInstantiate(String path) => 'AssetGenImage(\'$path\')'; | ||
|
||
@override | ||
bool isSupport(AssetType type) { | ||
/// https://api.flutter.dev/flutter/widgets/Image-class.html | ||
switch (type.mime) { | ||
case 'image/jpeg': | ||
case 'image/png': | ||
case 'image/gif': | ||
case 'image/bmp': | ||
case 'image/vnd.wap.wbmp': | ||
case 'image/webp': | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
@override | ||
bool get isConstConstructor => true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
packages/core/test_resources/actual_data/assets_flare_integrations.gen.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.