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:
parent
9d007937c6
commit
7436cc25eb
@ -503,7 +503,6 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
|
|||||||
return AnimatedPhysicalModel(
|
return AnimatedPhysicalModel(
|
||||||
curve: Curves.fastOutSlowIn,
|
curve: Curves.fastOutSlowIn,
|
||||||
duration: widget.animationDuration,
|
duration: widget.animationDuration,
|
||||||
shape: BoxShape.rectangle,
|
|
||||||
clipBehavior: widget.clipBehavior,
|
clipBehavior: widget.clipBehavior,
|
||||||
elevation: modelElevation,
|
elevation: modelElevation,
|
||||||
color: color,
|
color: color,
|
||||||
|
@ -1995,10 +1995,10 @@ class AnimatedPhysicalModel extends ImplicitlyAnimatedWidget {
|
|||||||
const AnimatedPhysicalModel({
|
const AnimatedPhysicalModel({
|
||||||
super.key,
|
super.key,
|
||||||
required this.child,
|
required this.child,
|
||||||
required this.shape,
|
this.shape = BoxShape.rectangle,
|
||||||
this.clipBehavior = Clip.none,
|
this.clipBehavior = Clip.none,
|
||||||
this.borderRadius = BorderRadius.zero,
|
this.borderRadius,
|
||||||
required this.elevation,
|
this.elevation = 0.0,
|
||||||
required this.color,
|
required this.color,
|
||||||
this.animateColor = true,
|
this.animateColor = true,
|
||||||
required this.shadowColor,
|
required this.shadowColor,
|
||||||
@ -2024,7 +2024,9 @@ class AnimatedPhysicalModel extends ImplicitlyAnimatedWidget {
|
|||||||
final Clip clipBehavior;
|
final Clip clipBehavior;
|
||||||
|
|
||||||
/// The target border radius of the rounded corners for a rectangle shape.
|
/// 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
|
/// The target z-coordinate relative to the parent at which to place this
|
||||||
/// physical object.
|
/// physical object.
|
||||||
@ -2068,10 +2070,26 @@ class _AnimatedPhysicalModelState extends AnimatedWidgetBaseState<AnimatedPhysic
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void forEachTween(TweenVisitor<dynamic> visitor) {
|
void forEachTween(TweenVisitor<dynamic> visitor) {
|
||||||
_borderRadius = visitor(_borderRadius, widget.borderRadius, (dynamic value) => BorderRadiusTween(begin: value as BorderRadius)) as BorderRadiusTween?;
|
_borderRadius = visitor(
|
||||||
_elevation = visitor(_elevation, widget.elevation, (dynamic value) => Tween<double>(begin: value as double)) as Tween<double>?;
|
_borderRadius,
|
||||||
_color = visitor(_color, widget.color, (dynamic value) => ColorTween(begin: value as Color)) as ColorTween?;
|
widget.borderRadius ?? BorderRadius.zero,
|
||||||
_shadowColor = visitor(_shadowColor, widget.shadowColor, (dynamic value) => ColorTween(begin: value as Color)) as ColorTween?;
|
(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
|
@override
|
||||||
|
@ -649,6 +649,29 @@ void main() {
|
|||||||
|
|
||||||
expect(secondCurvedAnimation.isDisposed, isTrue);
|
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,
|
Future<void> tapTest2and3(WidgetTester tester, Finder widgetFinder,
|
||||||
@ -904,9 +927,7 @@ class _TestAnimatedPhysicalModelWidgetState extends _TestAnimatedWidgetState {
|
|||||||
duration: duration,
|
duration: duration,
|
||||||
onEnd: widget.callback,
|
onEnd: widget.callback,
|
||||||
color: toggle ? Colors.red : Colors.green,
|
color: toggle ? Colors.red : Colors.green,
|
||||||
elevation: 0,
|
|
||||||
shadowColor: Colors.blue,
|
shadowColor: Colors.blue,
|
||||||
shape: BoxShape.rectangle,
|
|
||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user