Commit 8a365886 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Fixed scrollable TabBar flashing (#8741)

parent 71aaa5db
......@@ -99,6 +99,7 @@ class TabController extends ChangeNotifier {
_index = value;
if (duration != null) {
_indexIsChangingCount += 1;
notifyListeners(); // Because the value of indexIsChanging may have changed.
_animationController
..animateTo(_index.toDouble(), duration: duration, curve: curve).whenComplete(() {
_indexIsChangingCount -= 1;
......
This diff is collapsed.
......@@ -618,7 +618,7 @@ void main() {
expect(secondColor, equals(Colors.blue[500]));
});
testWidgets('TabBar unselectedLabelColor control test', (WidgetTester tester) async {
testWidgets('TabBarView page left and right test', (WidgetTester tester) async {
final TabController controller = new TabController(
vsync: const TestVSync(),
length: 2,
......@@ -635,29 +635,46 @@ void main() {
expect(controller.index, equals(0));
final TestGesture gesture = await tester.startGesture(const Point(100.0, 100.0));
TestGesture gesture = await tester.startGesture(const Point(100.0, 100.0));
expect(controller.index, equals(0));
await gesture.moveBy(const Offset(-380.0, 0.0));
// Drag to the left and right, by less than the TabBarView's width.
// The selected index (controller.index) should not change.
await gesture.moveBy(const Offset(-100.0, 0.0));
await gesture.moveBy(const Offset(100.0, 0.0));
expect(controller.index, equals(0));
expect(find.text('First'), findsOneWidget);
expect(find.text('Second'), findsNothing);
await gesture.moveBy(const Offset(-40.0, 0.0));
// Drag more than the TabBarView's width to the right. This forces
// the selected index to change to 1.
await gesture.moveBy(const Offset(-500.0, 0.0));
await gesture.up();
await tester.pump(); // start the scroll animation
await tester.pump(const Duration(seconds: 1)); // finish the scroll animation
expect(controller.index, equals(1));
expect(find.text('First'), findsNothing);
expect(find.text('Second'), findsOneWidget);
await gesture.moveBy(const Offset(-40.0, 0.0));
await tester.pump();
gesture = await tester.startGesture(const Point(100.0, 100.0));
expect(controller.index, equals(1));
await gesture.up();
await tester.pumpUntilNoTransientCallbacks();
// Drag to the left and right, by less than the TabBarView's width.
// The selected index (controller.index) should not change.
await gesture.moveBy(const Offset(-100.0, 0.0));
await gesture.moveBy(const Offset(100.0, 0.0));
expect(controller.index, equals(1));
expect(find.text('First'), findsNothing);
expect(find.text('Second'), findsOneWidget);
});
// Drag more than the TabBarView's width to the left. This forces
// the selected index to change back to 0.
await gesture.moveBy(const Offset(500.0, 0.0));
await gesture.up();
await tester.pump(); // start the scroll animation
await tester.pump(const Duration(seconds: 1)); // finish the scroll animation
expect(controller.index, equals(0));
expect(find.text('First'), findsOneWidget);
expect(find.text('Second'), findsNothing);
});
}
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