Skip to content

Commit

Permalink
Add clip option for navigator (#115775)
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai authored Nov 21, 2022
1 parent 7045a8b commit 567d004
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/flutter/lib/src/widgets/navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ class Navigator extends StatefulWidget {
/// Creates a widget that maintains a stack-based history of child widgets.
///
/// The [onGenerateRoute], [pages], [onGenerateInitialRoutes],
/// [transitionDelegate], [observers] arguments must not be null.
/// [transitionDelegate], [observers] arguments must not be null.
///
/// If the [pages] is not empty, the [onPopPage] must not be null.
const Navigator({
Expand All @@ -1398,6 +1398,7 @@ class Navigator extends StatefulWidget {
this.onUnknownRoute,
this.transitionDelegate = const DefaultTransitionDelegate<dynamic>(),
this.reportsRouteUpdateToEngine = false,
this.clipBehavior = Clip.hardEdge,
this.observers = const <NavigatorObserver>[],
this.requestFocus = true,
this.restorationScopeId,
Expand Down Expand Up @@ -1563,6 +1564,14 @@ class Navigator extends StatefulWidget {
/// Defaults to false.
final bool reportsRouteUpdateToEngine;

/// {@macro flutter.material.Material.clipBehavior}
///
/// In cases where clipping is not desired, consider setting this property to
/// [Clip.none].
///
/// Defaults to [Clip.hardEdge], and must not be null.
final Clip clipBehavior;

/// Whether or not the navigator and it's new topmost route should request focus
/// when the new route is pushed onto the navigator.
///
Expand Down Expand Up @@ -5253,6 +5262,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
bucket: bucket,
child: Overlay(
key: _overlayKey,
clipBehavior: widget.clipBehavior,
initialEntries: overlay == null ? _allRouteOverlayEntries.toList(growable: false) : const <OverlayEntry>[],
),
),
Expand Down
33 changes: 33 additions & 0 deletions packages/flutter/test/widgets/navigator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,39 @@ void main() {
expect(find.text('home'), findsOneWidget);
});

testWidgets('Navigator can set clip behavior', (WidgetTester tester) async {
const MaterialPage<void> page = MaterialPage<void>(child: Text('page'));
await tester.pumpWidget(
MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window),
child: Directionality(
textDirection: TextDirection.ltr,
child: Navigator(
pages: const <Page<void>>[page],
onPopPage: (_, __) => false,
),
),
),
);
// Default to hard edge.
expect(tester.widget<Overlay>(find.byType(Overlay)).clipBehavior, Clip.hardEdge);

await tester.pumpWidget(
MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window),
child: Directionality(
textDirection: TextDirection.ltr,
child: Navigator(
pages: const <Page<void>>[page],
clipBehavior: Clip.none,
onPopPage: (_, __) => false,
),
),
),
);
expect(tester.widget<Overlay>(find.byType(Overlay)).clipBehavior, Clip.none);
});

testWidgets('Zero transition page-based route correctly notifies observers when it is popped', (WidgetTester tester) async {
final List<Page<void>> pages = <Page<void>>[
const ZeroTransitionPage(name: 'Page 1'),
Expand Down

0 comments on commit 567d004

Please sign in to comment.