From 68c1b441be148bad55120ed507b95500a0c90f28 Mon Sep 17 00:00:00 2001 From: Smadey <365649304@qq.com> Date: Thu, 3 Sep 2020 07:45:06 +0800 Subject: [PATCH] Clamp TabController animation value when calc _DragAnimation.value (#64715) --- packages/flutter/lib/src/material/tabs.dart | 4 +- packages/flutter/test/material/tabs_test.dart | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 2b387dbd3cc..41f32a504a3 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -500,7 +500,9 @@ class _DragAnimation extends Animation with AnimationWithParentMixin[ + Builder(builder: (BuildContext context) { + firstColor = DefaultTextStyle.of(context).style.color; + return const Text('First'); + }), + Builder(builder: (BuildContext context) { + secondColor = DefaultTextStyle.of(context).style.color; + return const Text('Second'); + }), + ], + ), + ), + ); + + expect(firstColor, equals(Colors.white)); + expect(secondColor, equals(Colors.black)); + + controller.offset = 0.6; + await tester.pump(); + + expect(firstColor, equals(Color.lerp(Colors.white, Colors.black, 0.6))); + expect(secondColor, equals(Color.lerp(Colors.black, Colors.white, 0.6))); + + controller.index = 1; + await tester.pump(); + + expect(firstColor, equals(Colors.black)); + expect(secondColor, equals(Colors.white)); + + controller.offset = 0.6; + await tester.pump(); + + expect(firstColor, equals(Colors.black)); + expect(secondColor, equals(Colors.white)); + }); + testWidgets('Crash on dispose', (WidgetTester tester) async { await tester.pumpWidget(Padding(padding: const EdgeInsets.only(right: 200.0), child: TabBarDemo())); await tester.tap(find.byIcon(Icons.directions_bike));