Fix custom physics application in TabBarView (#58715)

This commit is contained in:
Kate Lovett
2020-06-04 16:43:03 -07:00
committed by GitHub
parent 78c2defae4
commit 3ec6978c9c
2 changed files with 22 additions and 2 deletions

View File

@@ -1179,7 +1179,7 @@ class TabBarView extends StatefulWidget {
_TabBarViewState createState() => _TabBarViewState();
}
final PageScrollPhysics _kTabBarViewPhysics = const PageScrollPhysics().applyTo(const ClampingScrollPhysics());
const PageScrollPhysics _kTabBarViewPhysics = PageScrollPhysics();
class _TabBarViewState extends State<TabBarView> {
TabController _controller;
@@ -1349,7 +1349,9 @@ class _TabBarViewState extends State<TabBarView> {
child: PageView(
dragStartBehavior: widget.dragStartBehavior,
controller: _pageController,
physics: widget.physics == null ? _kTabBarViewPhysics : _kTabBarViewPhysics.applyTo(widget.physics),
physics: widget.physics == null
? _kTabBarViewPhysics.applyTo(const ClampingScrollPhysics())
: _kTabBarViewPhysics.applyTo(widget.physics),
children: _childrenWithKey,
),
);

View File

@@ -2580,4 +2580,22 @@ void main() {
await tester.pumpAndSettle();
pageController.removeListener(pageControllerListener);
});
testWidgets('Setting BouncingScrollPhysics on TabBarView does not include ClampingScrollPhysics', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/57708
await tester.pumpWidget(MaterialApp(
home: DefaultTabController(
length: 10,
child: Scaffold(
body: TabBarView(
physics: const BouncingScrollPhysics(),
children: List<Widget>.generate(10, (int i) => Center(child: Text('index $i'))),
),
),
)
));
final PageView pageView = tester.widget<PageView>(find.byType(PageView));
expect(pageView.physics.toString().contains('ClampingScrollPhysics'), isFalse);
});
}