Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 2427d4f

Browse files
authored
Added clipBehavior on TabBarView (#103166)
1 parent c180971 commit 2427d4f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

packages/flutter/lib/src/material/tabs.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,7 @@ class TabBarView extends StatefulWidget {
13101310
this.physics,
13111311
this.dragStartBehavior = DragStartBehavior.start,
13121312
this.viewportFraction = 1.0,
1313+
this.clipBehavior = Clip.hardEdge,
13131314
}) : assert(children != null),
13141315
assert(dragStartBehavior != null);
13151316

@@ -1342,6 +1343,11 @@ class TabBarView extends StatefulWidget {
13421343
/// {@macro flutter.widgets.pageview.viewportFraction}
13431344
final double viewportFraction;
13441345

1346+
/// {@macro flutter.material.Material.clipBehavior}
1347+
///
1348+
/// Defaults to [Clip.hardEdge].
1349+
final Clip clipBehavior;
1350+
13451351
@override
13461352
State<TabBarView> createState() => _TabBarViewState();
13471353
}
@@ -1531,6 +1537,7 @@ class _TabBarViewState extends State<TabBarView> {
15311537
onNotification: _handleScrollNotification,
15321538
child: PageView(
15331539
dragStartBehavior: widget.dragStartBehavior,
1540+
clipBehavior: widget.clipBehavior,
15341541
controller: _pageController,
15351542
physics: widget.physics == null
15361543
? const PageScrollPhysics().applyTo(const ClampingScrollPhysics())

packages/flutter/test/material/tabs_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,45 @@ void main() {
11041104
expect(pageController.viewportFraction, 1);
11051105
});
11061106

1107+
testWidgets('TabBarView has clipBehavior Clip.hardEdge by default', (WidgetTester tester) async {
1108+
final List<Widget> tabs = <Widget>[const Text('First'), const Text('Second')];
1109+
1110+
Widget builder() {
1111+
return boilerplate(
1112+
child: DefaultTabController(
1113+
length: tabs.length,
1114+
child: TabBarView(
1115+
children: tabs,
1116+
),
1117+
),
1118+
);
1119+
}
1120+
1121+
await tester.pumpWidget(builder());
1122+
final TabBarView tabBarView = tester.widget(find.byType(TabBarView));
1123+
expect(tabBarView.clipBehavior, Clip.hardEdge);
1124+
});
1125+
1126+
testWidgets('TabBarView sets clipBehavior correctly', (WidgetTester tester) async {
1127+
final List<Widget> tabs = <Widget>[const Text('First'), const Text('Second')];
1128+
1129+
Widget builder() {
1130+
return boilerplate(
1131+
child: DefaultTabController(
1132+
length: tabs.length,
1133+
child: TabBarView(
1134+
clipBehavior: Clip.none,
1135+
children: tabs,
1136+
),
1137+
),
1138+
);
1139+
}
1140+
1141+
await tester.pumpWidget(builder());
1142+
final PageView pageView = tester.widget(find.byType(PageView));
1143+
expect(pageView.clipBehavior, Clip.none);
1144+
});
1145+
11071146
testWidgets('TabBar tap skips indicator animation when disabled in controller', (WidgetTester tester) async {
11081147
final List<String> tabs = <String>['A', 'B'];
11091148

0 commit comments

Comments
 (0)