Skip to content

Commit

Permalink
Added clipBehavior on TabBarView (#103166)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuncCccccc authored May 7, 2022
1 parent c180971 commit 2427d4f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/flutter/lib/src/material/tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ class TabBarView extends StatefulWidget {
this.physics,
this.dragStartBehavior = DragStartBehavior.start,
this.viewportFraction = 1.0,
this.clipBehavior = Clip.hardEdge,
}) : assert(children != null),
assert(dragStartBehavior != null);

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

/// {@macro flutter.material.Material.clipBehavior}
///
/// Defaults to [Clip.hardEdge].
final Clip clipBehavior;

@override
State<TabBarView> createState() => _TabBarViewState();
}
Expand Down Expand Up @@ -1531,6 +1537,7 @@ class _TabBarViewState extends State<TabBarView> {
onNotification: _handleScrollNotification,
child: PageView(
dragStartBehavior: widget.dragStartBehavior,
clipBehavior: widget.clipBehavior,
controller: _pageController,
physics: widget.physics == null
? const PageScrollPhysics().applyTo(const ClampingScrollPhysics())
Expand Down
39 changes: 39 additions & 0 deletions packages/flutter/test/material/tabs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,45 @@ void main() {
expect(pageController.viewportFraction, 1);
});

testWidgets('TabBarView has clipBehavior Clip.hardEdge by default', (WidgetTester tester) async {
final List<Widget> tabs = <Widget>[const Text('First'), const Text('Second')];

Widget builder() {
return boilerplate(
child: DefaultTabController(
length: tabs.length,
child: TabBarView(
children: tabs,
),
),
);
}

await tester.pumpWidget(builder());
final TabBarView tabBarView = tester.widget(find.byType(TabBarView));
expect(tabBarView.clipBehavior, Clip.hardEdge);
});

testWidgets('TabBarView sets clipBehavior correctly', (WidgetTester tester) async {
final List<Widget> tabs = <Widget>[const Text('First'), const Text('Second')];

Widget builder() {
return boilerplate(
child: DefaultTabController(
length: tabs.length,
child: TabBarView(
clipBehavior: Clip.none,
children: tabs,
),
),
);
}

await tester.pumpWidget(builder());
final PageView pageView = tester.widget(find.byType(PageView));
expect(pageView.clipBehavior, Clip.none);
});

testWidgets('TabBar tap skips indicator animation when disabled in controller', (WidgetTester tester) async {
final List<String> tabs = <String>['A', 'B'];

Expand Down

0 comments on commit 2427d4f

Please sign in to comment.