Unverified Commit 68c1b441 authored by Smadey's avatar Smadey Committed by GitHub

Clamp TabController animation value when calc _DragAnimation.value (#64715)

parent 280e6d6c
......@@ -500,7 +500,9 @@ class _DragAnimation extends Animation<double> with AnimationWithParentMixin<dou
@override
double get value {
assert(!controller.indexIsChanging);
return (controller.animation.value - index.toDouble()).abs().clamp(0.0, 1.0) as double;
final double controllerMaxValue = (controller.length - 1).toDouble();
final double controllerValue = controller.animation.value.clamp(0.0, controllerMaxValue) as double;
return (controllerValue - index.toDouble()).abs().clamp(0.0, 1.0) as double;
}
}
......
......@@ -2671,6 +2671,57 @@ void main() {
expect(pageView.physics.toString().contains('ClampingScrollPhysics'), isFalse);
});
testWidgets('TabController changes offset attribute', (WidgetTester tester) async {
final TabController controller = TabController(
vsync: const TestVSync(),
length: 2,
);
Color firstColor;
Color secondColor;
await tester.pumpWidget(
boilerplate(
child: TabBar(
controller: controller,
labelColor: Colors.white,
unselectedLabelColor: Colors.black,
tabs: <Widget>[
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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment