Skip to content

Commit

Permalink
Merge pull request #243 from conceptadev/feature/fix-box-widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Apr 3, 2024
2 parents e01cf66 + 0456e83 commit 96e598e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
3 changes: 2 additions & 1 deletion lib/src/factory/mix_provider_data.dart
Expand Up @@ -5,6 +5,7 @@ import '../attributes/variant_attribute.dart';
import '../core/attribute.dart';
import '../core/attributes_map.dart';
import '../helpers/compare_mixin.dart';
import '../helpers/constants.dart';
import '../theme/token_resolver.dart';
import '../widgets/pressable/pressable_util.dart';
import 'style_mix.dart';
Expand Down Expand Up @@ -187,7 +188,7 @@ class AnimatedData with Comparable {

factory AnimatedData.withDefaults({Duration? duration, Curve? curve}) {
return AnimatedData(
duration: duration ?? const Duration(milliseconds: 150),
duration: duration ?? kDefaultAnimationDuration,
curve: curve ?? Curves.linear,
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/helpers/constants.dart
@@ -0,0 +1 @@
const kDefaultAnimationDuration = Duration(milliseconds: 200);
28 changes: 16 additions & 12 deletions lib/src/specs/container/box_spec.dart
Expand Up @@ -84,26 +84,30 @@ class BoxSpec extends Spec<BoxSpec> {

@override
BoxSpec lerp(BoxSpec? other, double t) {
if (other == null) return this;

return BoxSpec(
alignment: AlignmentGeometry.lerp(alignment, other?.alignment, t),
padding: EdgeInsetsGeometry.lerp(padding, other?.padding, t),
margin: EdgeInsetsGeometry.lerp(margin, other?.margin, t),
constraints: BoxConstraints.lerp(constraints, other?.constraints, t),
decoration: Decoration.lerp(decoration, other?.decoration, t),
alignment: AlignmentGeometry.lerp(alignment, other.alignment, t),
padding: EdgeInsetsGeometry.lerp(padding, other.padding, t),
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,
other.foregroundDecoration,
t,
),
transform: Matrix4Tween(begin: transform, end: other?.transform).lerp(t),
transform: transform != null && other.transform != null
? Matrix4Tween(begin: transform, end: other.transform).lerp(t)
: lerpSnap(transform, other.transform, t),
transformAlignment: AlignmentGeometry.lerp(
transformAlignment,
other?.transformAlignment,
other.transformAlignment,
t,
),
clipBehavior: lerpSnap(clipBehavior, other?.clipBehavior, t),
width: lerpDouble(width, other?.width, t),
height: lerpDouble(height, other?.height, t),
clipBehavior: lerpSnap(clipBehavior, other.clipBehavior, t),
width: lerpDouble(width, other.width, t),
height: lerpDouble(height, other.height, t),
);
}

Expand All @@ -123,7 +127,7 @@ class BoxSpec extends Spec<BoxSpec> {
];
}

class BoxSpecTween extends Tween<BoxSpec> {
class BoxSpecTween extends Tween<BoxSpec?> {
BoxSpecTween({super.begin, super.end});

@override
Expand Down
14 changes: 7 additions & 7 deletions lib/src/specs/container/box_widget.dart
Expand Up @@ -55,16 +55,16 @@ class Box extends StyledWidget {
// This method uses `withMix` to get the `MixData` and then applies it to `MixedBox`,
// effectively styling the [child].
return withMix(context, (mix) {
final style = BoxSpec.of(mix);
final spec = BoxSpec.of(mix);

return mix.isAnimated
? AnimatedMixedBox(
style: style,
spec: spec,
duration: mix.animation!.duration,
curve: mix.animation!.curve,
child: child,
)
: MixedBox(spec: style, child: child);
: MixedBox(spec: spec, child: child);
});
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ class MixedBox extends StatelessWidget {

class AnimatedMixedBox extends ImplicitlyAnimatedWidget {
const AnimatedMixedBox({
required this.style,
required this.spec,
super.key,
this.child,
required super.duration,
Expand All @@ -105,7 +105,7 @@ class AnimatedMixedBox extends ImplicitlyAnimatedWidget {
});

final Widget? child;
final BoxSpec style;
final BoxSpec spec;

@override
AnimatedWidgetBaseState<AnimatedMixedBox> createState() =>
Expand All @@ -121,9 +121,9 @@ class _AnimatedBoxSpecWidgetState
void forEachTween(TweenVisitor<dynamic> visitor) {
_boxSpec = visitor(
_boxSpec,
widget.style,
widget.spec,
// ignore: avoid-dynamic
(dynamic value) => BoxSpecTween(begin: value as BoxSpec),
(dynamic value) => BoxSpecTween(begin: value as BoxSpec?),
) as BoxSpecTween?;
}

Expand Down
16 changes: 8 additions & 8 deletions lib/src/specs/icon/icon_spec.dart
Expand Up @@ -44,17 +44,17 @@ class IconSpec extends Spec<IconSpec> {
}

@override
IconSpec lerp(IconSpec other, double t) {
IconSpec lerp(IconSpec? other, double t) {
return IconSpec(
color: Color.lerp(color, other.color, t),
size: lerpDouble(size, other.size, t),
weight: lerpDouble(weight, other.weight, t),
grade: lerpDouble(grade, other.grade, t),
opticalSize: lerpDouble(opticalSize, other.opticalSize, t),
shadows: Shadow.lerpList(shadows, other.shadows, t),
color: Color.lerp(color, other?.color, t),
size: lerpDouble(size, other?.size, t),
weight: lerpDouble(weight, other?.weight, t),
grade: lerpDouble(grade, other?.grade, t),
opticalSize: lerpDouble(opticalSize, other?.opticalSize, t),
shadows: Shadow.lerpList(shadows, other?.shadows, t),
textDirection: textDirection,
applyTextScaling: applyTextScaling,
fill: lerpDouble(fill, other.fill, t),
fill: lerpDouble(fill, other?.fill, t),
);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/src/widgets/pressable/pressable_widget.dart
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import '../../factory/style_mix.dart';
import '../../helpers/constants.dart';
import '../../specs/container/box_widget.dart';
import '../../utils/custom_focusable_action_detector.dart';
import 'pressable_state.dart';
Expand All @@ -21,7 +22,7 @@ class PressableBox extends StatelessWidget {
@Deprecated('Use hitTestBehavior instead') HitTestBehavior? behavior,
this.hitTestBehavior,
@Deprecated('Use AnimatedStyle instead')
this.animationDuration = const Duration(milliseconds: 125),
this.animationDuration = kDefaultAnimationDuration,
@Deprecated('Use AnimatedStyle instead')
this.animationCurve = Curves.linear,
this.disabled = false,
Expand Down Expand Up @@ -94,7 +95,7 @@ class Pressable extends _PressableBuilderWidget {
onPress: onPress ?? onPressed,
hitTestBehavior:
hitTestBehavior ?? behavior ?? HitTestBehavior.opaque,
unpressDelay: unpressDelay ?? const Duration(milliseconds: 150),
unpressDelay: unpressDelay ?? kDefaultAnimationDuration,
);

@override
Expand Down

0 comments on commit 96e598e

Please sign in to comment.