Add clip option for navigator (#115775)
This commit is contained in:
@@ -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({
|
||||
@@ -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,
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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>[],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user