From f6cde06af3002602c7fd5393c612d0d774e265f2 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 6 Dec 2016 10:48:45 -0800 Subject: [PATCH] Correct scrollable tabs fling velocity (#7170) --- packages/flutter/lib/src/material/tabs.dart | 3 +- packages/flutter/test/material/tabs_test.dart | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 1a894c1715..9098c124e0 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -430,9 +430,8 @@ class _TabsScrollBehavior extends BoundedBehavior { if (!isScrollable) return null; - double velocityPerSecond = velocity * 1000.0; return new BoundedFrictionSimulation( - _kTabBarScrollDrag, position, velocityPerSecond, minScrollOffset, maxScrollOffset + _kTabBarScrollDrag, position, velocity, minScrollOffset, maxScrollOffset ); } diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index ebf81fabc4..623b5126bf 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -309,4 +309,43 @@ void main() { expect(find.text('RIGHT CHILD'), findsNothing); }); + // A regression test for https://github.com/flutter/flutter/issues/7133 + testWidgets('TabBar fling velocity', (WidgetTester tester) async { + List tabs = ['AAAAAA', 'BBBBBB', 'CCCCCC', 'DDDDDD', 'EEEEEE', 'FFFFFF', 'GGGGGG', 'HHHHHH', 'IIIIII', 'JJJJJJ', 'KKKKKK', 'LLLLLL']; + int index = 0; + + await tester.pumpWidget( + new MaterialApp( + home: new Align( + alignment: FractionalOffset.topLeft, + child: new SizedBox( + width: 300.0, + height: 200.0, + child: new TabBarSelection( + values: tabs, + child: new Scaffold( + appBar: new AppBar( + title: new Text('tabs'), + bottom: new TabBar( + isScrollable: true, + labels: new Map.fromIterable(tabs, value: (String tab) => new TabLabel(text: tab)), + ), + ), + body: new TabBarView( + children: tabs.map((String name) => new Text('${index++}')).toList(), + ), + ), + ), + ), + ), + ), + ); + + // After a small slow fling to the left, we expect the second item to still be visible. + await tester.fling(find.text('AAAAAA'), new Offset(-25.0, 0.0), 100.0); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); // finish the scroll animation + final RenderBox box = tester.renderObject(find.text('BBBBBB')); + expect(box.localToGlobal(Point.origin).x, greaterThan(0.0)); + }); }