Skip to content

Commit

Permalink
Add default arguments to AnimatedPhysicalModel (#147424)
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-thegrate committed May 2, 2024
1 parent 9d00793 commit 7436cc2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
1 change: 0 additions & 1 deletion packages/flutter/lib/src/material/material.dart
Expand Up @@ -503,7 +503,6 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
return AnimatedPhysicalModel(
curve: Curves.fastOutSlowIn,
duration: widget.animationDuration,
shape: BoxShape.rectangle,
clipBehavior: widget.clipBehavior,
elevation: modelElevation,
color: color,
Expand Down
34 changes: 26 additions & 8 deletions packages/flutter/lib/src/widgets/implicit_animations.dart
Expand Up @@ -1995,10 +1995,10 @@ class AnimatedPhysicalModel extends ImplicitlyAnimatedWidget {
const AnimatedPhysicalModel({
super.key,
required this.child,
required this.shape,
this.shape = BoxShape.rectangle,
this.clipBehavior = Clip.none,
this.borderRadius = BorderRadius.zero,
required this.elevation,
this.borderRadius,
this.elevation = 0.0,
required this.color,
this.animateColor = true,
required this.shadowColor,
Expand All @@ -2024,7 +2024,9 @@ class AnimatedPhysicalModel extends ImplicitlyAnimatedWidget {
final Clip clipBehavior;

/// The target border radius of the rounded corners for a rectangle shape.
final BorderRadius borderRadius;
///
/// If null, treated as [BorderRadius.zero].
final BorderRadius? borderRadius;

/// The target z-coordinate relative to the parent at which to place this
/// physical object.
Expand Down Expand Up @@ -2068,10 +2070,26 @@ class _AnimatedPhysicalModelState extends AnimatedWidgetBaseState<AnimatedPhysic

@override
void forEachTween(TweenVisitor<dynamic> visitor) {
_borderRadius = visitor(_borderRadius, widget.borderRadius, (dynamic value) => BorderRadiusTween(begin: value as BorderRadius)) as BorderRadiusTween?;
_elevation = visitor(_elevation, widget.elevation, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?;
_color = visitor(_color, widget.color, (dynamic value) => ColorTween(begin: value as Color)) as ColorTween?;
_shadowColor = visitor(_shadowColor, widget.shadowColor, (dynamic value) => ColorTween(begin: value as Color)) as ColorTween?;
_borderRadius = visitor(
_borderRadius,
widget.borderRadius ?? BorderRadius.zero,
(dynamic value) => BorderRadiusTween(begin: value as BorderRadius),
) as BorderRadiusTween?;
_elevation = visitor(
_elevation,
widget.elevation,
(dynamic value) => Tween<double>(begin: value as double),
) as Tween<double>?;
_color = visitor(
_color,
widget.color,
(dynamic value) => ColorTween(begin: value as Color),
) as ColorTween?;
_shadowColor = visitor(
_shadowColor,
widget.shadowColor,
(dynamic value) => ColorTween(begin: value as Color),
) as ColorTween?;
}

@override
Expand Down
25 changes: 23 additions & 2 deletions packages/flutter/test/widgets/implicit_animations_test.dart
Expand Up @@ -649,6 +649,29 @@ void main() {

expect(secondCurvedAnimation.isDisposed, isTrue);
});

group('Verify that default args match non-animated variants', () {
const Widget child = SizedBox.shrink();
const Color color = Color(0x00000000);

testWidgets('PhysicalModel default args', (WidgetTester tester) async {
const AnimatedPhysicalModel animatedPhysicalModel = AnimatedPhysicalModel(
duration: Duration.zero,
color: color,
shadowColor: color,
child: child,
);
const PhysicalModel physicalModel = PhysicalModel(
color: color,
shadowColor: color,
child: child,
);
expect(identical(animatedPhysicalModel.shape, physicalModel.shape), isTrue);
expect(identical(animatedPhysicalModel.clipBehavior, physicalModel.clipBehavior), isTrue);
expect(identical(animatedPhysicalModel.borderRadius, physicalModel.borderRadius), isTrue);
});
// TODO(nate-thegrate): add every class!
});
}

Future<void> tapTest2and3(WidgetTester tester, Finder widgetFinder,
Expand Down Expand Up @@ -904,9 +927,7 @@ class _TestAnimatedPhysicalModelWidgetState extends _TestAnimatedWidgetState {
duration: duration,
onEnd: widget.callback,
color: toggle ? Colors.red : Colors.green,
elevation: 0,
shadowColor: Colors.blue,
shape: BoxShape.rectangle,
child: child,
);
}
Expand Down

0 comments on commit 7436cc2

Please sign in to comment.