Repository navigation
[go_router] Expose Navigator clipBehavior on ShellRoute and StatefulShellBranch #12646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 5 commits into
flutter:main
from
m1roxx:go-router-shell-clip-behavior
Sep 30, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
252a3b4
[go_router] Expose Navigator clipBehavior on ShellRoute and StatefulS…
m1roxx 582fabb
[go_router] Use a pending changelog for the batch release process
m1roxx db18e37
[go_router] Resolve the clip behavior without changing NavigatorBuilder
m1roxx 919818f
[go_router] Address review feedback on clipBehavior
m1roxx 0d00d94
Merge branch 'main' of https://github.com/flutter/packages into go-ro…
m1roxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/go_router/pending_changelogs/shell_route_clip_behavior.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| changelog: | | ||
| - Adds `clipBehavior` to `ShellRoute` and `StatefulShellBranch`, forwarded to the nested `Navigator`. | ||
| version: minor |
208 changes: 208 additions & 0 deletions
208
packages/go_router/test/shell_route_clip_behavior_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:go_router/go_router.dart'; | ||
| import 'package:material_ui/material_ui.dart'; | ||
|
|
||
| import 'test_helpers.dart'; | ||
|
|
||
| /// Reads the clip behavior of the [Navigator] identified by [navigatorKey]. | ||
| /// | ||
| /// Offstage widgets are included so that the Navigators of inactive | ||
| /// [StatefulShellBranch]es can be inspected too. | ||
| Clip clipBehaviorOf(WidgetTester tester, GlobalKey<NavigatorState> navigatorKey) => | ||
| tester.widget<Navigator>(find.byKey(navigatorKey, skipOffstage: false)).clipBehavior; | ||
|
|
||
| class _ShellRouteData extends ShellRouteData { | ||
| const _ShellRouteData(); | ||
|
|
||
| @override | ||
| Widget builder(BuildContext context, GoRouterState state, Widget navigator) => navigator; | ||
| } | ||
|
|
||
| /// Reads the description of the `clipBehavior` diagnostics property of the | ||
| /// given [route], or null if the property is hidden at its default value. | ||
| String? clipBehaviorDiagnosticOf(ShellRoute route) { | ||
| final builder = DiagnosticPropertiesBuilder(); | ||
| route.debugFillProperties(builder); | ||
| return builder.properties | ||
| .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) | ||
| .where((DiagnosticsNode node) => node.name == 'clipBehavior') | ||
| .map((DiagnosticsNode node) => node.toDescription()) | ||
| .firstOrNull; | ||
| } | ||
|
|
||
| void main() { | ||
| group('ShellRoute', () { | ||
| test('includes a non-default clipBehavior in debugFillProperties', () { | ||
| ShellRoute shellRoute({Clip clipBehavior = Clip.hardEdge}) => ShellRoute( | ||
| clipBehavior: clipBehavior, | ||
| builder: (_, _, Widget child) => child, | ||
| routes: <RouteBase>[GoRoute(path: '/', builder: (_, _) => const Text('Home'))], | ||
| ); | ||
|
|
||
| expect(clipBehaviorDiagnosticOf(shellRoute()), isNull); | ||
| expect(clipBehaviorDiagnosticOf(shellRoute(clipBehavior: Clip.none)), 'none'); | ||
| }); | ||
|
|
||
| testWidgets('clips the nested Navigator by default', (WidgetTester tester) async { | ||
| final navigatorKey = GlobalKey<NavigatorState>(debugLabel: 'shell'); | ||
| await createRouter(<RouteBase>[ | ||
| ShellRoute( | ||
| navigatorKey: navigatorKey, | ||
| builder: (_, _, Widget child) => child, | ||
| routes: <RouteBase>[GoRoute(path: '/', builder: (_, _) => const Text('Home'))], | ||
| ), | ||
| ], tester); | ||
|
|
||
| expect(clipBehaviorOf(tester, navigatorKey), Clip.hardEdge); | ||
| }); | ||
|
|
||
| testWidgets('forwards clipBehavior to the nested Navigator', (WidgetTester tester) async { | ||
| final navigatorKey = GlobalKey<NavigatorState>(debugLabel: 'shell'); | ||
| await createRouter(<RouteBase>[ | ||
| ShellRoute( | ||
| navigatorKey: navigatorKey, | ||
| clipBehavior: Clip.none, | ||
| builder: (_, _, Widget child) => child, | ||
| routes: <RouteBase>[GoRoute(path: '/', builder: (_, _) => const Text('Home'))], | ||
| ), | ||
| ], tester); | ||
|
|
||
| expect(clipBehaviorOf(tester, navigatorKey), Clip.none); | ||
| }); | ||
|
|
||
| testWidgets('forwards clipBehavior to the nested Navigator when using pageBuilder', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| final navigatorKey = GlobalKey<NavigatorState>(debugLabel: 'shell'); | ||
| await createRouter(<RouteBase>[ | ||
| ShellRoute( | ||
| navigatorKey: navigatorKey, | ||
| clipBehavior: Clip.antiAlias, | ||
| pageBuilder: (_, _, Widget child) => MaterialPage<void>(child: child), | ||
| routes: <RouteBase>[GoRoute(path: '/', builder: (_, _) => const Text('Home'))], | ||
| ), | ||
| ], tester); | ||
|
|
||
| expect(clipBehaviorOf(tester, navigatorKey), Clip.antiAlias); | ||
| }); | ||
| }); | ||
|
|
||
| group('StatefulShellBranch', () { | ||
| testWidgets('clips the branch Navigator by default', (WidgetTester tester) async { | ||
| final navigatorKey = GlobalKey<NavigatorState>(debugLabel: 'branch'); | ||
| await createRouter(<RouteBase>[ | ||
| StatefulShellRoute.indexedStack( | ||
| builder: (_, _, StatefulNavigationShell shell) => shell, | ||
| branches: <StatefulShellBranch>[ | ||
| StatefulShellBranch( | ||
| navigatorKey: navigatorKey, | ||
| routes: <RouteBase>[GoRoute(path: '/', builder: (_, _) => const Text('A'))], | ||
| ), | ||
| ], | ||
| ), | ||
| ], tester); | ||
|
|
||
| expect(clipBehaviorOf(tester, navigatorKey), Clip.hardEdge); | ||
| }); | ||
|
|
||
| testWidgets('forwards clipBehavior per branch', (WidgetTester tester) async { | ||
| final keyA = GlobalKey<NavigatorState>(debugLabel: 'a'); | ||
| final keyB = GlobalKey<NavigatorState>(debugLabel: 'b'); | ||
| final root = GlobalKey<NavigatorState>(debugLabel: 'root'); | ||
| await createRouter( | ||
| <RouteBase>[ | ||
| StatefulShellRoute.indexedStack( | ||
| builder: (_, _, StatefulNavigationShell shell) => shell, | ||
| branches: <StatefulShellBranch>[ | ||
| StatefulShellBranch( | ||
| navigatorKey: keyA, | ||
| clipBehavior: Clip.none, | ||
| routes: <RouteBase>[GoRoute(path: '/a', builder: (_, _) => const Text('A'))], | ||
| ), | ||
| StatefulShellBranch( | ||
| navigatorKey: keyB, | ||
| routes: <RouteBase>[GoRoute(path: '/b', builder: (_, _) => const Text('B'))], | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| tester, | ||
| navigatorKey: root, | ||
| initialLocation: '/a', | ||
| ); | ||
|
|
||
| expect(clipBehaviorOf(tester, keyA), Clip.none); | ||
|
|
||
| root.currentContext!.go('/b'); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| // Each branch keeps its own clip behavior; the loaded branches stay in | ||
| // the tree because StatefulShellRoute preserves their state. | ||
| expect(clipBehaviorOf(tester, keyA), Clip.none); | ||
| expect(clipBehaviorOf(tester, keyB), Clip.hardEdge); | ||
| }); | ||
|
|
||
| testWidgets('forwards clipBehavior to preloaded branches', (WidgetTester tester) async { | ||
| final keyA = GlobalKey<NavigatorState>(debugLabel: 'a'); | ||
| final keyB = GlobalKey<NavigatorState>(debugLabel: 'b'); | ||
| await createRouter( | ||
| <RouteBase>[ | ||
| StatefulShellRoute.indexedStack( | ||
| builder: (_, _, StatefulNavigationShell shell) => shell, | ||
| branches: <StatefulShellBranch>[ | ||
| StatefulShellBranch( | ||
| navigatorKey: keyA, | ||
| routes: <RouteBase>[GoRoute(path: '/a', builder: (_, _) => const Text('A'))], | ||
| ), | ||
| StatefulShellBranch( | ||
| navigatorKey: keyB, | ||
| preload: true, | ||
| clipBehavior: Clip.none, | ||
| routes: <RouteBase>[GoRoute(path: '/b', builder: (_, _) => const Text('B'))], | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| tester, | ||
| initialLocation: '/a', | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(clipBehaviorOf(tester, keyB), Clip.none); | ||
| }); | ||
| }); | ||
|
|
||
| group('typed routes', () { | ||
| test(r'ShellRouteData.$route forwards clipBehavior', () { | ||
| final routes = <RouteBase>[GoRoute(path: '/', builder: (_, _) => const Text('Home'))]; | ||
|
|
||
| expect( | ||
| ShellRouteData.$route(factory: (_) => const _ShellRouteData(), routes: routes).clipBehavior, | ||
| Clip.hardEdge, | ||
| ); | ||
| expect( | ||
| ShellRouteData.$route( | ||
| factory: (_) => const _ShellRouteData(), | ||
| clipBehavior: Clip.none, | ||
| routes: routes, | ||
| ).clipBehavior, | ||
| Clip.none, | ||
| ); | ||
| }); | ||
|
|
||
| test(r'StatefulShellBranchData.$branch forwards clipBehavior', () { | ||
| final routes = <RouteBase>[GoRoute(path: '/', builder: (_, _) => const Text('Home'))]; | ||
|
|
||
| expect(StatefulShellBranchData.$branch(routes: routes).clipBehavior, Clip.hardEdge); | ||
| expect( | ||
| StatefulShellBranchData.$branch(routes: routes, clipBehavior: Clip.none).clipBehavior, | ||
| Clip.none, | ||
| ); | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.