Add default arguments to AnimatedPhysicalModel (#147424)

Currently, `PhysicalModel` has [default arguments](2e806700b9/packages/flutter/lib/src/widgets/basic.dart (L1093)) for `shape` and `elevation`, but `AnimatedPhysicalModel` [does not](2e806700b9/packages/flutter/lib/src/widgets/implicit_animations.dart (L1998)).

This pull request makes both classes consistent.
This commit is contained in:
Nate 2024-05-02 15:59:07 -06:00 committed by GitHub
parent 9d007937c6
commit 7436cc25eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 11 deletions

View File

@ -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,

View File

@ -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,
@ -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.
@ -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

View File

@ -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,
@ -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,
);
}