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

Commit 567d004

Browse files
authored
Add clip option for navigator (#115775)
1 parent 7045a8b commit 567d004

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

packages/flutter/lib/src/widgets/navigator.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ class Navigator extends StatefulWidget {
13851385
/// Creates a widget that maintains a stack-based history of child widgets.
13861386
///
13871387
/// The [onGenerateRoute], [pages], [onGenerateInitialRoutes],
1388-
/// [transitionDelegate], [observers] arguments must not be null.
1388+
/// [transitionDelegate], [observers] arguments must not be null.
13891389
///
13901390
/// If the [pages] is not empty, the [onPopPage] must not be null.
13911391
const Navigator({
@@ -1398,6 +1398,7 @@ class Navigator extends StatefulWidget {
13981398
this.onUnknownRoute,
13991399
this.transitionDelegate = const DefaultTransitionDelegate<dynamic>(),
14001400
this.reportsRouteUpdateToEngine = false,
1401+
this.clipBehavior = Clip.hardEdge,
14011402
this.observers = const <NavigatorObserver>[],
14021403
this.requestFocus = true,
14031404
this.restorationScopeId,
@@ -1563,6 +1564,14 @@ class Navigator extends StatefulWidget {
15631564
/// Defaults to false.
15641565
final bool reportsRouteUpdateToEngine;
15651566

1567+
/// {@macro flutter.material.Material.clipBehavior}
1568+
///
1569+
/// In cases where clipping is not desired, consider setting this property to
1570+
/// [Clip.none].
1571+
///
1572+
/// Defaults to [Clip.hardEdge], and must not be null.
1573+
final Clip clipBehavior;
1574+
15661575
/// Whether or not the navigator and it's new topmost route should request focus
15671576
/// when the new route is pushed onto the navigator.
15681577
///
@@ -5253,6 +5262,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
52535262
bucket: bucket,
52545263
child: Overlay(
52555264
key: _overlayKey,
5265+
clipBehavior: widget.clipBehavior,
52565266
initialEntries: overlay == null ? _allRouteOverlayEntries.toList(growable: false) : const <OverlayEntry>[],
52575267
),
52585268
),

packages/flutter/test/widgets/navigator_test.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,39 @@ void main() {
200200
expect(find.text('home'), findsOneWidget);
201201
});
202202

203+
testWidgets('Navigator can set clip behavior', (WidgetTester tester) async {
204+
const MaterialPage<void> page = MaterialPage<void>(child: Text('page'));
205+
await tester.pumpWidget(
206+
MediaQuery(
207+
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window),
208+
child: Directionality(
209+
textDirection: TextDirection.ltr,
210+
child: Navigator(
211+
pages: const <Page<void>>[page],
212+
onPopPage: (_, __) => false,
213+
),
214+
),
215+
),
216+
);
217+
// Default to hard edge.
218+
expect(tester.widget<Overlay>(find.byType(Overlay)).clipBehavior, Clip.hardEdge);
219+
220+
await tester.pumpWidget(
221+
MediaQuery(
222+
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window),
223+
child: Directionality(
224+
textDirection: TextDirection.ltr,
225+
child: Navigator(
226+
pages: const <Page<void>>[page],
227+
clipBehavior: Clip.none,
228+
onPopPage: (_, __) => false,
229+
),
230+
),
231+
),
232+
);
233+
expect(tester.widget<Overlay>(find.byType(Overlay)).clipBehavior, Clip.none);
234+
});
235+
203236
testWidgets('Zero transition page-based route correctly notifies observers when it is popped', (WidgetTester tester) async {
204237
final List<Page<void>> pages = <Page<void>>[
205238
const ZeroTransitionPage(name: 'Page 1'),

0 commit comments

Comments
 (0)