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 default arguments to AnimatedPhysicalModel #147424

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the explicit default value for borderRadius?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-animated class has a nullable border radius, so this change makes them consistent.

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