Fix TabBar jag when user interrupts ballistic scroll (#64380)
This commit is contained in:
@@ -1347,6 +1347,8 @@ class _TabBarViewState extends State<TabBarView> {
|
||||
} else if (notification is ScrollEndNotification) {
|
||||
_controller.index = _pageController.page.round();
|
||||
_currentIndex = _controller.index;
|
||||
if (!_controller.indexIsChanging)
|
||||
_controller.offset = (_pageController.page - _controller.index).clamp(-1.0, 1.0) as double;
|
||||
}
|
||||
_warpUnderwayCount -= 1;
|
||||
|
||||
|
||||
@@ -2728,6 +2728,50 @@ void main() {
|
||||
// There was a time where this would throw an exception
|
||||
// because we tried to send a notification on dispose.
|
||||
});
|
||||
|
||||
testWidgets('TabController\'s animation value should be in sync with TabBarView\'s scroll value when user interrupts ballistic scroll', (WidgetTester tester) async {
|
||||
final TabController tabController = TabController(
|
||||
vsync: const TestVSync(),
|
||||
length: 3,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: SizedBox.expand(
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 400.0,
|
||||
height: 400.0,
|
||||
child: TabBarView(
|
||||
controller: tabController,
|
||||
children: const <Widget>[
|
||||
Center(child: Text('0')),
|
||||
Center(child: Text('1')),
|
||||
Center(child: Text('2')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
final PageView pageView = tester.widget(find.byType(PageView));
|
||||
final PageController pageController = pageView.controller;
|
||||
final ScrollPosition position = pageController.position;
|
||||
|
||||
expect(tabController.index, 0);
|
||||
expect(position.pixels, 0.0);
|
||||
|
||||
pageController.jumpTo(300.0);
|
||||
await tester.pump();
|
||||
expect(tabController.animation.value, pageController.page);
|
||||
|
||||
// Touch TabBarView while ballistic scrolling is happening and
|
||||
// check if tabController's animation value properly follows page value.
|
||||
await tester.startGesture(tester.getCenter(find.byType(PageView)));
|
||||
await tester.pump();
|
||||
expect(tabController.animation.value, pageController.page);
|
||||
});
|
||||
}
|
||||
|
||||
class KeepAliveInk extends StatefulWidget {
|
||||
|
||||
Reference in New Issue
Block a user