From 588dc69f3080394640b79e57b02cde99a53a2dc5 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Mon, 25 Mar 2024 13:38:57 -0400 Subject: [PATCH] Adjustments --- lib/src/attributes/scalars/scalar_util.dart | 2 ++ lib/src/factory/mix_provider_data.dart | 10 ++++++++-- lib/src/specs/container/box_spec.dart | 8 ++++---- lib/src/specs/container/box_util.dart | 3 +++ lib/src/specs/container/box_widget.dart | 13 ++++++++++--- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/src/attributes/scalars/scalar_util.dart b/lib/src/attributes/scalars/scalar_util.dart index a1e7c896a..dc8c26b24 100644 --- a/lib/src/attributes/scalars/scalar_util.dart +++ b/lib/src/attributes/scalars/scalar_util.dart @@ -465,6 +465,8 @@ class OffsetUtility extends MixUtility { const OffsetUtility(super.builder); T call(double dx, double dy) => builder(Offset(dx, dy)); + + T zero() => builder(Offset.zero); } class FontSizeUtility extends SizingUtility { diff --git a/lib/src/factory/mix_provider_data.dart b/lib/src/factory/mix_provider_data.dart index e14b73768..25ee31062 100644 --- a/lib/src/factory/mix_provider_data.dart +++ b/lib/src/factory/mix_provider_data.dart @@ -183,11 +183,17 @@ M? _mergeAttributes(Iterable mergeables) { class AnimatedData with Comparable { final Duration duration; final Curve curve; - const AnimatedData({required this.duration, required this.curve}); + factory AnimatedData.withDefaults({Duration? duration, Curve? curve}) { + return AnimatedData( + duration: duration ?? const Duration(milliseconds: 150), + curve: curve ?? Curves.linear, + ); + } + @override - List get props => [duration, curve]; + get props => [duration, curve]; } Iterable _applyStyleBuilder( diff --git a/lib/src/specs/container/box_spec.dart b/lib/src/specs/container/box_spec.dart index c2b8828e1..1e58b4394 100644 --- a/lib/src/specs/container/box_spec.dart +++ b/lib/src/specs/container/box_spec.dart @@ -123,13 +123,13 @@ class BoxSpec extends Spec { ]; } -class BoxSpecTween extends Tween { +class BoxSpecTween extends Tween { BoxSpecTween({super.begin, super.end}); @override - BoxSpec? lerp(double t) { - if (begin == null) return end; - if (end == null) return begin; + BoxSpec lerp(double t) { + if (begin == null && end == null) return const BoxSpec.empty(); + if (begin == null) return end!; return begin!.lerp(end!, t); } diff --git a/lib/src/specs/container/box_util.dart b/lib/src/specs/container/box_util.dart index f6dc3484f..879127e20 100644 --- a/lib/src/specs/container/box_util.dart +++ b/lib/src/specs/container/box_util.dart @@ -7,6 +7,7 @@ import '../../attributes/constraints/constraints_dto.dart'; import '../../attributes/constraints/constraints_util.dart'; import '../../attributes/decoration/decoration_dto.dart'; import '../../attributes/decoration/decoration_util.dart'; +import '../../attributes/gradient/gradient_util.dart'; import '../../attributes/scalars/scalar_util.dart'; import '../../attributes/shadow/shadow_util.dart'; import '../../attributes/spacing/spacing_dto.dart'; @@ -322,6 +323,8 @@ class BoxSpecUtility extends SpecUtility { ElevationUtility get elevation => decoration.elevation; + GradientUtility get gradient => decoration.gradient; + ShapeDecorationUtility get shapeDecoration => ShapeDecorationUtility((decoration) => only(decoration: decoration)); diff --git a/lib/src/specs/container/box_widget.dart b/lib/src/specs/container/box_widget.dart index aa463e4ea..008ce498d 100644 --- a/lib/src/specs/container/box_widget.dart +++ b/lib/src/specs/container/box_widget.dart @@ -106,11 +106,18 @@ class MixedBox extends StatelessWidget { final MixData mix; @override Widget build(BuildContext context) { - // Get MixData from this widget or the nearest MixProvider. + return BoxSpecWidget(spec: BoxSpec.of(mix), child: child); + } +} - // Retrieve styling properties from MixData. Use default properties if MixData is not provided. - final spec = BoxSpec.of(mix); +class BoxSpecWidget extends StatelessWidget { + const BoxSpecWidget({required this.spec, super.key, this.child}); + final Widget? child; + final BoxSpec spec; + + @override + Widget build(BuildContext context) { return Container( alignment: spec.alignment, padding: spec.padding,