Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new attribute to foregroundDecoration #193

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/src/specs/container/box_attribute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BoxSpecAttribute extends SpecAttribute<BoxSpecAttribute, BoxSpec> {
final SpacingDto? margin;
final BoxConstraintsDto? constraints;
final DecorationDto? decoration;
final DecorationDto? foregroundDecoration;
final Matrix4? transform;
final Clip? clipBehavior;
final double? width;
Expand All @@ -24,6 +25,7 @@ class BoxSpecAttribute extends SpecAttribute<BoxSpecAttribute, BoxSpec> {
this.margin,
this.constraints,
this.decoration,
this.foregroundDecoration,
this.transform,
this.clipBehavior,
this.width,
Expand All @@ -38,6 +40,7 @@ class BoxSpecAttribute extends SpecAttribute<BoxSpecAttribute, BoxSpec> {
margin: margin?.resolve(mix),
constraints: constraints?.resolve(mix),
decoration: decoration?.resolve(mix),
foregroundDecoration: foregroundDecoration?.resolve(mix),
transform: transform,
clipBehavior: clipBehavior,
width: width,
Expand All @@ -55,6 +58,9 @@ class BoxSpecAttribute extends SpecAttribute<BoxSpecAttribute, BoxSpec> {
margin: margin?.merge(other.margin) ?? other.margin,
constraints: constraints?.merge(other.constraints) ?? other.constraints,
decoration: decoration?.merge(other.decoration) ?? other.decoration,
foregroundDecoration:
foregroundDecoration?.merge(other.foregroundDecoration) ??
other.foregroundDecoration,
transform: other.transform ?? transform,
clipBehavior: other.clipBehavior ?? clipBehavior,
width: other.width ?? width,
Expand All @@ -69,6 +75,7 @@ class BoxSpecAttribute extends SpecAttribute<BoxSpecAttribute, BoxSpec> {
margin,
constraints,
decoration,
foregroundDecoration,
transform,
clipBehavior,
width,
Expand Down
11 changes: 11 additions & 0 deletions lib/src/specs/container/box_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BoxSpec extends Spec<BoxSpec> {
final EdgeInsetsGeometry? margin;
final BoxConstraints? constraints;
final Decoration? decoration;
final Decoration? foregroundDecoration;
final Matrix4? transform;
final Clip? clipBehavior;
final double? width;
Expand All @@ -24,6 +25,7 @@ class BoxSpec extends Spec<BoxSpec> {
required this.margin,
required this.constraints,
required this.decoration,
required this.foregroundDecoration,
required this.transform,
required this.clipBehavior,
required this.width,
Expand All @@ -36,6 +38,7 @@ class BoxSpec extends Spec<BoxSpec> {
margin = null,
constraints = null,
decoration = null,
foregroundDecoration = null,
transform = null,
width = null,
height = null,
Expand All @@ -53,6 +56,7 @@ class BoxSpec extends Spec<BoxSpec> {
EdgeInsetsGeometry? margin,
BoxConstraints? constraints,
Decoration? decoration,
Decoration? foregroundDecoration,
double? width,
double? height,
Matrix4? transform,
Expand All @@ -65,6 +69,7 @@ class BoxSpec extends Spec<BoxSpec> {
margin: margin ?? this.margin,
constraints: constraints ?? this.constraints,
decoration: decoration ?? this.decoration,
foregroundDecoration: foregroundDecoration ?? this.foregroundDecoration,
transform: transform ?? this.transform,
clipBehavior: clipBehavior ?? this.clipBehavior,
width: width ?? this.width,
Expand All @@ -80,6 +85,11 @@ class BoxSpec extends Spec<BoxSpec> {
margin: EdgeInsetsGeometry.lerp(margin, other.margin, t),
constraints: BoxConstraints.lerp(constraints, other.constraints, t),
decoration: Decoration.lerp(decoration, other.decoration, t),
foregroundDecoration: Decoration.lerp(
foregroundDecoration,
other.foregroundDecoration,
t,
),
transform: Matrix4Tween(begin: transform, end: other.transform).lerp(t),
clipBehavior: lerpSnap(clipBehavior, other.clipBehavior, t),
width: lerpDouble(width, other.width, t),
Expand All @@ -96,6 +106,7 @@ class BoxSpec extends Spec<BoxSpec> {
margin,
constraints,
decoration,
foregroundDecoration,
transform,
clipBehavior,
];
Expand Down
9 changes: 9 additions & 0 deletions lib/src/specs/container/box_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ class BoxSpecUtility extends SpecUtility<BoxSpecAttribute> {
);
}

BoxDecorationUtility<BoxSpecAttribute> get foregroundDecoration {
return BoxDecorationUtility(
(foregroundDecoration) =>
only(foregroundDecoration: foregroundDecoration),
);
}

AlignmentUtility<BoxSpecAttribute> get alignment {
return AlignmentUtility((alignment) => only(alignment: alignment));
}
Expand Down Expand Up @@ -364,6 +371,7 @@ class BoxSpecUtility extends SpecUtility<BoxSpecAttribute> {
SpacingDto? padding,
SpacingDto? margin,
DecorationDto? decoration,
DecorationDto? foregroundDecoration,
BoxConstraintsDto? constraints,
double? width,
double? height,
Expand All @@ -376,6 +384,7 @@ class BoxSpecUtility extends SpecUtility<BoxSpecAttribute> {
margin: margin,
constraints: constraints,
decoration: decoration,
foregroundDecoration: foregroundDecoration,
transform: transform,
clipBehavior: clipBehavior,
width: width,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/specs/container/box_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class MixedBox extends StatelessWidget {
alignment: spec.alignment,
padding: spec.padding,
decoration: spec.decoration,
foregroundDecoration: spec.foregroundDecoration,
width: spec.width,
height: spec.height,
constraints: spec.constraints,
Expand Down Expand Up @@ -225,6 +226,7 @@ class AnimatedMixedBox extends StatelessWidget {
width: spec.width,
height: spec.height,
constraints: spec.constraints,
foregroundDecoration: spec.foregroundDecoration,
margin: spec.margin,
transform: spec.transform,
clipBehavior: spec.clipBehavior ?? Clip.none,
Expand Down
20 changes: 20 additions & 0 deletions test/src/specs/container/box_spec_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void main() {
margin: const EdgeInsets.only(top: 8.0, bottom: 8.0),
constraints: const BoxConstraints(maxWidth: 300.0, minHeight: 200.0),
decoration: const BoxDecoration(color: Colors.blue),
foregroundDecoration: const BoxDecoration(color: Colors.purple),
transform: Matrix4.translationValues(10.0, 10.0, 0.0),
clipBehavior: Clip.antiAlias,
);
Expand All @@ -71,6 +72,8 @@ void main() {
expect(copiedSpec.constraints,
const BoxConstraints(maxWidth: 300.0, minHeight: 200.0));
expect(copiedSpec.decoration, const BoxDecoration(color: Colors.blue));
expect(copiedSpec.foregroundDecoration,
const BoxDecoration(color: Colors.purple));

expect(copiedSpec.transform, Matrix4.translationValues(10.0, 10.0, 0.0));
expect(copiedSpec.clipBehavior, Clip.antiAlias);
Expand All @@ -87,6 +90,7 @@ void main() {
margin: const EdgeInsets.only(top: 4.0),
constraints: const BoxConstraints(maxWidth: 200.0),
decoration: const BoxDecoration(color: Colors.red),
foregroundDecoration: const BoxDecoration(color: Colors.blue),
transform: Matrix4.identity(),
clipBehavior: Clip.none,
);
Expand All @@ -99,6 +103,7 @@ void main() {
margin: const EdgeInsets.only(top: 8.0),
constraints: const BoxConstraints(maxWidth: 400.0),
decoration: const BoxDecoration(color: Colors.blue),
foregroundDecoration: const BoxDecoration(color: Colors.red),
transform: Matrix4.rotationZ(0.5),
clipBehavior: Clip.antiAlias,
);
Expand Down Expand Up @@ -127,6 +132,13 @@ void main() {
end: const BoxDecoration(color: Colors.blue))
.lerp(t));

expect(
lerpedSpec.foregroundDecoration,
DecorationTween(
begin: const BoxDecoration(color: Colors.blue),
end: const BoxDecoration(color: Colors.red))
.lerp(t));

expect(lerpedSpec.width, lerpDouble(300, 400, t));
expect(lerpedSpec.height, lerpDouble(200, 300, t));

Expand All @@ -147,6 +159,7 @@ void main() {
margin: const EdgeInsets.only(top: 4.0),
constraints: const BoxConstraints(maxWidth: 200.0),
decoration: const BoxDecoration(color: Colors.red),
foregroundDecoration: const BoxDecoration(color: Colors.blue),
transform: Matrix4.identity(),
clipBehavior: Clip.none,
);
Expand All @@ -159,6 +172,7 @@ void main() {
margin: const EdgeInsets.only(top: 4.0),
constraints: const BoxConstraints(maxWidth: 200.0),
decoration: const BoxDecoration(color: Colors.red),
foregroundDecoration: const BoxDecoration(color: Colors.blue),
transform: Matrix4.identity(),
clipBehavior: Clip.none,
);
Expand All @@ -173,6 +187,8 @@ void main() {
clipBehavior: Clip.antiAlias,
constraints: const BoxConstraintsDto(maxHeight: 100),
decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)),
foregroundDecoration:
const BoxDecorationDto(color: ColorDto(Colors.blue)),
height: 100,
margin: const SpacingDto.only(
bottom: 10,
Expand All @@ -192,6 +208,8 @@ void main() {
clipBehavior: Clip.antiAliasWithSaveLayer,
constraints: const BoxConstraintsDto(maxHeight: 200),
decoration: const BoxDecorationDto(color: ColorDto(Colors.red)),
foregroundDecoration:
const BoxDecorationDto(color: ColorDto(Colors.amber)),
height: 200,
margin: const SpacingDto.only(
bottom: 20,
Expand All @@ -213,6 +231,8 @@ void main() {
const BoxConstraintsDto(maxHeight: 200));
expect(mergedBoxSpecAttribute.decoration,
const BoxDecorationDto(color: ColorDto(Colors.red)));
expect(mergedBoxSpecAttribute.foregroundDecoration,
const BoxDecorationDto(color: ColorDto(Colors.amber)));
expect(mergedBoxSpecAttribute.height, 200);
expect(
mergedBoxSpecAttribute.margin,
Expand Down
36 changes: 36 additions & 0 deletions test/src/specs/container/box_util_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,42 @@ void main() {

expect(container.width, 10);
});

test('decoration() returns correct instance', () {
final container = boxUtility.decoration(
color: Colors.amber,
borderRadius: BorderRadius.circular(10),
);

expect(container.decoration!.color, const ColorDto(Colors.amber));

final decorationDTO = container.decoration as BoxDecorationDto;
expect(
decorationDTO.borderRadius,
BorderRadiusGeometryDto.from(BorderRadius.circular(10)),
);
});

test('foregroundDecoration() returns correct instance', () {
final container = boxUtility.foregroundDecoration(
color: Colors.amber,
borderRadius: BorderRadius.circular(10),
);

expect(
container.foregroundDecoration!.color,
const ColorDto(Colors.amber),
reason: 'The color is not correct',
);

final foregroundDecorationDTO =
container.foregroundDecoration as BoxDecorationDto;
expect(
foregroundDecorationDTO.borderRadius,
BorderRadiusGeometryDto.from(BorderRadius.circular(10)),
reason: 'The BorderRadius is not correct',
);
});
},
);
}
Loading