Fix custom physics application in TabBarView (#58715)
This commit is contained in:
@@ -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,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user