Fix for negative padding from a curve in AnimatedPadding. (#52072)
* Fix for negative padding from a curve in AnimatedPadding. * Added a EdgeInsets.clamp function that would return an EdgeInsets instance instead of a _MixedEdgeInsets used by the base class. This was causing some tests to fail that didn't have a text direction.
This commit is contained in:
parent
2e18cd347e
commit
1c3ebad904
@ -503,6 +503,16 @@ class EdgeInsets extends EdgeInsetsGeometry {
|
||||
return super.add(other);
|
||||
}
|
||||
|
||||
@override
|
||||
EdgeInsetsGeometry clamp(EdgeInsetsGeometry min, EdgeInsetsGeometry max) {
|
||||
return EdgeInsets.fromLTRB(
|
||||
_left.clamp(min._left, max._left) as double,
|
||||
_top.clamp(min._top, max._top) as double,
|
||||
_right.clamp(min._right, max._right) as double,
|
||||
_bottom.clamp(min._bottom, max._bottom) as double,
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns the difference between two [EdgeInsets].
|
||||
EdgeInsets operator -(EdgeInsets other) {
|
||||
return EdgeInsets.fromLTRB(
|
||||
|
@ -834,7 +834,9 @@ class _AnimatedPaddingState extends AnimatedWidgetBaseState<AnimatedPadding> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: _padding.evaluate(animation),
|
||||
padding: _padding
|
||||
.evaluate(animation)
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity),
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
@ -58,4 +58,44 @@ void main() {
|
||||
expect(tester.getSize(find.byKey(target)), const Size(700.0, 600.0));
|
||||
expect(tester.getTopRight(find.byKey(target)), const Offset(700.0, 0.0));
|
||||
});
|
||||
|
||||
testWidgets('AnimatedPadding animated padding clamped to positive values', (WidgetTester tester) async {
|
||||
final Key target = UniqueKey();
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: AnimatedPadding(
|
||||
curve: Curves.easeInOutBack, // will cause negative padding during overshoot
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.only(right: 50.0),
|
||||
child: SizedBox.expand(key: target),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byKey(target)), const Size(750.0, 600.0));
|
||||
expect(tester.getTopRight(find.byKey(target)), const Offset(750.0, 0.0));
|
||||
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: AnimatedPadding(
|
||||
curve: Curves.easeInOutBack,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.only(right: 0.0),
|
||||
child: SizedBox.expand(key: target),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.getSize(find.byKey(target)), const Size(750.0, 600.0));
|
||||
expect(tester.getTopRight(find.byKey(target)), const Offset(750.0, 0.0));
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 128));
|
||||
// Curve would have made the padding negative a this point if it is not clamped.
|
||||
expect(tester.getSize(find.byKey(target)), const Size(800.0, 600.0));
|
||||
expect(tester.getTopRight(find.byKey(target)), const Offset(800.0, 0.0));
|
||||
});
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user