BorderTween.lerp supports null begin/end values (#73992)

This commit is contained in:
Hans Muller
2021-01-14 17:16:04 -08:00
committed by GitHub
parent 8d72307c47
commit f63eb0b281
2 changed files with 46 additions and 2 deletions

View File

@@ -143,7 +143,7 @@ class BorderRadiusTween extends Tween<BorderRadius> {
/// [Border.lerp].
///
/// See [Tween] for a discussion on how to use interpolation objects.
class BorderTween extends Tween<Border> {
class BorderTween extends Tween<Border?> {
/// Creates a [Border] tween.
///
/// The [begin] and [end] properties may be null; the null value
@@ -152,7 +152,11 @@ class BorderTween extends Tween<Border> {
/// Returns the value this variable has at the given animation clock value.
@override
Border lerp(double t) => Border.lerp(begin, end, t)!;
Border? lerp(double t) {
if (begin == null || end == null)
return t < 0.5 ? begin : end;
return Border.lerp(begin!, end!, t);
}
}
/// An interpolation between two [Matrix4]s.

View File

@@ -1292,6 +1292,46 @@ void main() {
initialTrailingTextToLargeTitleOffset.dy.abs(),
);
});
testWidgets('Null NavigationBar border transition', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/71389
await tester.pumpWidget(
const CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Page 1'),
border: null,
),
child: Placeholder(),
),
),
);
tester.state<NavigatorState>(find.byType(Navigator)).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return const CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Page 2'),
border: null,
),
child: Placeholder(),
);
},
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(find.text('Page 1'), findsNothing);
expect(find.text('Page 2'), findsOneWidget);
await tester.tap(find.text(String.fromCharCode(CupertinoIcons.back.codePoint)));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(find.text('Page 1'), findsOneWidget);
expect(find.text('Page 2'), findsNothing);
});
}
class _ExpectStyles extends StatelessWidget {