diff --git a/lib/src/attributes/decoration/decoration_util.dart b/lib/src/attributes/decoration/decoration_util.dart index 0ca1bf4a7..d1cf30647 100644 --- a/lib/src/attributes/decoration/decoration_util.dart +++ b/lib/src/attributes/decoration/decoration_util.dart @@ -76,7 +76,8 @@ class BoxDecorationUtility BlendModeUtility get backgroundBlendMode { return BlendModeUtility( - (blendMode) => _only(backgroundBlendMode: blendMode)); + (blendMode) => _only(backgroundBlendMode: blendMode), + ); } BorderDirectionalUtility get borderDirectional { diff --git a/lib/src/attributes/decoration/image/decoration_image_dto.dart b/lib/src/attributes/decoration/image/decoration_image_dto.dart index 02e1b81ca..303d81e70 100644 --- a/lib/src/attributes/decoration/image/decoration_image_dto.dart +++ b/lib/src/attributes/decoration/image/decoration_image_dto.dart @@ -3,6 +3,7 @@ import 'package:flutter/widgets.dart'; import '../../../core/attribute.dart'; import '../../../factory/mix_provider_data.dart'; +@immutable class DecorationImageDto extends Dto with Mergeable { final ImageProvider? image; @@ -25,8 +26,7 @@ class DecorationImageDto extends Dto this.isAntiAlias, }); - static DecorationImageDto? maybeFrom(DecorationImage? image) { - if (image == null) return null; + static DecorationImageDto from(DecorationImage image) { return DecorationImageDto( image: image.image, fit: image.fit, @@ -39,6 +39,10 @@ class DecorationImageDto extends Dto ); } + static DecorationImageDto? maybeFrom(DecorationImage? image) { + return image != null ? from(image) : null; + } + @override DecorationImageDto merge(covariant DecorationImageDto? other) { return DecorationImageDto( @@ -53,6 +57,27 @@ class DecorationImageDto extends Dto ); } + @override + DecorationImage resolve(MixData mix) { + const defaultDecoration = DecorationImage(image: AssetImage('')); + + assert( + image != null, + 'ImageProvider is required for DecorationImage', + ); + + return DecorationImage( + image: image!, + fit: fit, + alignment: alignment ?? defaultDecoration.alignment, + centerSlice: centerSlice, + repeat: repeat ?? defaultDecoration.repeat, + filterQuality: filterQuality ?? defaultDecoration.filterQuality, + invertColors: invertColors ?? defaultDecoration.invertColors, + isAntiAlias: isAntiAlias ?? defaultDecoration.isAntiAlias, + ); + } + @override List get props => [ image, @@ -64,18 +89,4 @@ class DecorationImageDto extends Dto invertColors, isAntiAlias, ]; - - @override - DecorationImage resolve(MixData mix) { - return DecorationImage( - image: image ?? const AssetImage(''), - fit: fit, - alignment: alignment ?? Alignment.center, - centerSlice: centerSlice, - repeat: repeat ?? ImageRepeat.noRepeat, - filterQuality: filterQuality ?? FilterQuality.low, - invertColors: invertColors ?? false, - isAntiAlias: isAntiAlias ?? false, - ); - } } diff --git a/lib/src/attributes/decoration/image/decoration_image_util.dart b/lib/src/attributes/decoration/image/decoration_image_util.dart index 34766b1f1..45a7e4154 100644 --- a/lib/src/attributes/decoration/image/decoration_image_util.dart +++ b/lib/src/attributes/decoration/image/decoration_image_util.dart @@ -6,16 +6,31 @@ import 'decoration_image_dto.dart'; class DecorationImageUtility extends MixUtility { - DecorationImageUtility(super.builder); + const DecorationImageUtility(super.builder); - T call( - ImageProvider image, - ) => - builder( - DecorationImageDto( - image: image, - ), - ); + T _only({ + ImageProvider? image, + BoxFit? fit, + AlignmentGeometry? alignment, + Rect? centerSlice, + ImageRepeat? repeat, + FilterQuality? filterQuality, + bool? invertColors, + bool? isAntiAlias, + }) { + return builder( + DecorationImageDto( + image: image, + fit: fit, + alignment: alignment, + centerSlice: centerSlice, + repeat: repeat, + filterQuality: filterQuality, + invertColors: invertColors, + isAntiAlias: isAntiAlias, + ), + ); + } BoxFitUtility get fit { return BoxFitUtility((fit) => _only(fit: fit)); @@ -35,7 +50,8 @@ class DecorationImageUtility FilterQualityUtility get filterQuality { return FilterQualityUtility( - (filterQuality) => _only(filterQuality: filterQuality)); + (filterQuality) => _only(filterQuality: filterQuality), + ); } BoolUtility get invertColors { @@ -46,27 +62,5 @@ class DecorationImageUtility return BoolUtility((isAntiAlias) => _only(isAntiAlias: isAntiAlias)); } - T _only({ - ImageProvider? image, - BoxFit? fit, - AlignmentGeometry? alignment, - Rect? centerSlice, - ImageRepeat? repeat, - FilterQuality? filterQuality, - bool? invertColors, - bool? isAntiAlias, - }) { - return builder( - DecorationImageDto( - image: image, - fit: fit, - alignment: alignment, - centerSlice: centerSlice, - repeat: repeat, - filterQuality: filterQuality, - invertColors: invertColors, - isAntiAlias: isAntiAlias, - ), - ); - } + T call(ImageProvider image) => builder(DecorationImageDto(image: image)); }