mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Clamp TabController animation value when calc _DragAnimation.value (#64715)
This commit is contained in:
parent
280e6d6c01
commit
68c1b441be
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user