Skip to content

Commit

Permalink
Small adjustments and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Feb 3, 2024
1 parent 5122410 commit 0812986
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 50 deletions.
3 changes: 2 additions & 1 deletion lib/src/attributes/decoration/decoration_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class BoxDecorationUtility<T extends StyleAttribute>

BlendModeUtility<T> get backgroundBlendMode {
return BlendModeUtility(
(blendMode) => _only(backgroundBlendMode: blendMode));
(blendMode) => _only(backgroundBlendMode: blendMode),
);
}

BorderDirectionalUtility<T> get borderDirectional {
Expand Down
43 changes: 27 additions & 16 deletions lib/src/attributes/decoration/image/decoration_image_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/widgets.dart';
import '../../../core/attribute.dart';
import '../../../factory/mix_provider_data.dart';

@immutable
class DecorationImageDto extends Dto<DecorationImage>
with Mergeable<DecorationImageDto> {
final ImageProvider? image;
Expand All @@ -25,8 +26,7 @@ class DecorationImageDto extends Dto<DecorationImage>
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,
Expand All @@ -39,6 +39,10 @@ class DecorationImageDto extends Dto<DecorationImage>
);
}

static DecorationImageDto? maybeFrom(DecorationImage? image) {
return image != null ? from(image) : null;
}

@override
DecorationImageDto merge(covariant DecorationImageDto? other) {
return DecorationImageDto(
Expand All @@ -53,6 +57,27 @@ class DecorationImageDto extends Dto<DecorationImage>
);
}

@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<Object?> get props => [
image,
Expand All @@ -64,18 +89,4 @@ class DecorationImageDto extends Dto<DecorationImage>
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,
);
}
}
60 changes: 27 additions & 33 deletions lib/src/attributes/decoration/image/decoration_image_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@ import 'decoration_image_dto.dart';

class DecorationImageUtility<T extends StyleAttribute>
extends MixUtility<T, DecorationImageDto> {
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<T> get fit {
return BoxFitUtility((fit) => _only(fit: fit));
Expand All @@ -35,7 +50,8 @@ class DecorationImageUtility<T extends StyleAttribute>

FilterQualityUtility<T> get filterQuality {
return FilterQualityUtility(
(filterQuality) => _only(filterQuality: filterQuality));
(filterQuality) => _only(filterQuality: filterQuality),
);
}

BoolUtility<T> get invertColors {
Expand All @@ -46,27 +62,5 @@ class DecorationImageUtility<T extends StyleAttribute>
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));
}

0 comments on commit 0812986

Please sign in to comment.