Skip to content

Commit

Permalink
Added backgroundBlendMode to decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Jan 29, 2024
1 parent d2e2c8a commit 4fe9015
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/src/attributes/decoration/decoration_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class BoxDecorationDto extends DecorationDto<BoxDecoration> {
final BoxBorderDto? border;
final BorderRadiusGeometryDto? borderRadius;
final BoxShape? shape;
final BlendMode? backgroundBlendMode;

const BoxDecorationDto({
super.color,
Expand All @@ -106,6 +107,7 @@ class BoxDecorationDto extends DecorationDto<BoxDecoration> {
super.gradient,
super.boxShadow,
this.shape,
this.backgroundBlendMode,
});

/// Creates a [BoxDecorationDto] from a given [BoxDecoration].
Expand All @@ -117,6 +119,7 @@ class BoxDecorationDto extends DecorationDto<BoxDecoration> {
gradient: GradientDto.maybeFrom(decoration.gradient),
boxShadow: decoration.boxShadow?.map(BoxShadowDto.from).toList(),
shape: decoration.shape,
backgroundBlendMode: decoration.backgroundBlendMode,
);
}

Expand All @@ -140,13 +143,17 @@ class BoxDecorationDto extends DecorationDto<BoxDecoration> {
gradient: gradient?.merge(other.gradient) ?? other.gradient,
boxShadow: boxShadow?.merge(other.boxShadow) ?? other.boxShadow,
shape: other.shape ?? shape,
backgroundBlendMode: other.backgroundBlendMode ?? backgroundBlendMode,
);
}

@override
bool isMergeable() {
// is only mergeable if no other properties are set besides: color, boxShadow, and gradient
return border == null && borderRadius == null && shape == null;
return border == null &&
borderRadius == null &&
shape == null &&
backgroundBlendMode == null;
}

/// Resolves this [BoxDecorationDto] with a given [MixData] to a [BoxDecoration]
Expand All @@ -158,13 +165,21 @@ class BoxDecorationDto extends DecorationDto<BoxDecoration> {
borderRadius: borderRadius?.resolve(mix),
boxShadow: boxShadow?.map((e) => e.resolve(mix)).toList(),
gradient: gradient?.resolve(mix),
backgroundBlendMode: backgroundBlendMode,
shape: shape ?? BoxShape.rectangle,
);
}

@override
List<Object?> get props =>
[color, border, borderRadius, gradient, boxShadow, shape];
List<Object?> get props => [
color,
border,
borderRadius,
gradient,
boxShadow,
shape,
backgroundBlendMode,
];
}

@immutable
Expand Down
9 changes: 9 additions & 0 deletions lib/src/attributes/decoration/decoration_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class BoxDecorationUtility<T extends StyleAttribute>
GradientDto? gradient,
List<BoxShadowDto>? boxShadow,
BoxShape? shape,
BlendMode? backgroundBlendMode,
}) {
return builder(
BoxDecorationDto(
Expand All @@ -56,6 +57,7 @@ class BoxDecorationUtility<T extends StyleAttribute>
gradient: gradient,
boxShadow: boxShadow,
shape: shape,
backgroundBlendMode: backgroundBlendMode,
),
);
}
Expand All @@ -68,6 +70,11 @@ class BoxDecorationUtility<T extends StyleAttribute>
return BorderUtility((border) => _only(border: border));
}

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

BorderDirectionalUtility<T> get borderDirectional {
return BorderDirectionalUtility((borderDirectional) {
return _only(border: borderDirectional);
Expand Down Expand Up @@ -121,6 +128,7 @@ class BoxDecorationUtility<T extends StyleAttribute>
Gradient? gradient,
List<BoxShadow>? boxShadow,
BoxShape? shape,
BlendMode? backgroundBlendMode,
}) {
return _only(
color: color?.toDto(),
Expand All @@ -129,6 +137,7 @@ class BoxDecorationUtility<T extends StyleAttribute>
gradient: gradient?.toDto(),
boxShadow: boxShadow?.toDto(),
shape: shape,
backgroundBlendMode: backgroundBlendMode,
);
}
}
Expand Down

0 comments on commit 4fe9015

Please sign in to comment.