@@ -1433,6 +1433,208 @@ void main() {
14331433 },
14341434 );
14351435 });
1436+
1437+ group ('Shell navigator semantics boundary' , () {
1438+ testWidgets ('Chrome painted before a ShellRoute Navigator stays in the '
1439+ 'semantics tree alongside routed content' , (WidgetTester tester) async {
1440+ final SemanticsHandle semantics = tester.ensureSemantics ();
1441+
1442+ final router = GoRouter (
1443+ initialLocation: '/a' ,
1444+ routes: < RouteBase > [
1445+ ShellRoute (
1446+ builder: (BuildContext context, GoRouterState state, Widget child) {
1447+ return Row (
1448+ children: < Widget > [
1449+ Semantics (
1450+ container: true ,
1451+ label: 'chrome' ,
1452+ child: const SizedBox (width: 40 , height: 40 ),
1453+ ),
1454+ Expanded (child: child),
1455+ ],
1456+ );
1457+ },
1458+ routes: < RouteBase > [
1459+ GoRoute (
1460+ path: '/a' ,
1461+ builder: (BuildContext context, GoRouterState state) {
1462+ return const Text ('content-a' );
1463+ },
1464+ ),
1465+ GoRoute (
1466+ path: '/b' ,
1467+ builder: (BuildContext context, GoRouterState state) {
1468+ return const Text ('content-b' );
1469+ },
1470+ ),
1471+ ],
1472+ ),
1473+ ],
1474+ );
1475+ addTearDown (router.dispose);
1476+
1477+ await tester.pumpWidget (MaterialApp .router (routerConfig: router));
1478+ await tester.pumpAndSettle ();
1479+
1480+ // Without the Semantics(container: true) wrap around the shell's
1481+ // Navigator, the route's ModalBarrier (BlockSemantics) drops the
1482+ // chrome painted before it, because a Navigator does not
1483+ // establish a semantics boundary. See
1484+ // https://github.com/flutter/flutter/issues/135656.
1485+ expect (find.bySemanticsLabel ('chrome' ), findsOneWidget);
1486+ expect (find.bySemanticsLabel ('content-a' ), findsOneWidget);
1487+
1488+ // Navigation between two routes within the same shell keeps
1489+ // working, and the chrome remains exposed after the rebuild.
1490+ router.go ('/b' );
1491+ await tester.pumpAndSettle ();
1492+
1493+ expect (find.bySemanticsLabel ('chrome' ), findsOneWidget);
1494+ expect (find.bySemanticsLabel ('content-b' ), findsOneWidget);
1495+ expect (find.bySemanticsLabel ('content-a' ), findsNothing);
1496+
1497+ semantics.dispose ();
1498+ });
1499+
1500+ testWidgets ('ShellRoute Navigator is wrapped in a Semantics(container: true) '
1501+ 'boundary' , (WidgetTester tester) async {
1502+ final shellNavigatorKey = GlobalKey <NavigatorState >();
1503+ final router = GoRouter (
1504+ initialLocation: '/' ,
1505+ routes: < RouteBase > [
1506+ ShellRoute (
1507+ navigatorKey: shellNavigatorKey,
1508+ builder: (BuildContext context, GoRouterState state, Widget child) {
1509+ return child;
1510+ },
1511+ routes: < RouteBase > [
1512+ GoRoute (
1513+ path: '/' ,
1514+ builder: (BuildContext context, GoRouterState state) {
1515+ return const Text ('content' );
1516+ },
1517+ ),
1518+ ],
1519+ ),
1520+ ],
1521+ );
1522+ addTearDown (router.dispose);
1523+
1524+ await tester.pumpWidget (MaterialApp .router (routerConfig: router));
1525+ await tester.pumpAndSettle ();
1526+
1527+ final Iterable <Semantics > ancestorSemantics = tester.widgetList <Semantics >(
1528+ find.ancestor (of: find.byKey (shellNavigatorKey), matching: find.byType (Semantics )),
1529+ );
1530+ expect (
1531+ ancestorSemantics.first.container,
1532+ isTrue,
1533+ reason:
1534+ 'The nearest Semantics ancestor of the shell Navigator '
1535+ 'should be the container boundary added by go_router.' ,
1536+ );
1537+ });
1538+
1539+ testWidgets ('Root GoRouter Navigator is not wrapped in an extra Semantics '
1540+ 'container boundary' , (WidgetTester tester) async {
1541+ final rootNavigatorKey = GlobalKey <NavigatorState >();
1542+ final router = GoRouter (
1543+ navigatorKey: rootNavigatorKey,
1544+ initialLocation: '/' ,
1545+ routes: < RouteBase > [
1546+ GoRoute (
1547+ path: '/' ,
1548+ builder: (BuildContext context, GoRouterState state) {
1549+ return const Text ('content' );
1550+ },
1551+ ),
1552+ ],
1553+ );
1554+ addTearDown (router.dispose);
1555+
1556+ await tester.pumpWidget (MaterialApp .router (routerConfig: router));
1557+ await tester.pumpAndSettle ();
1558+
1559+ // The root navigator has no earlier-painted siblings by
1560+ // construction, so go_router must not add the shell-only
1561+ // Semantics(container: true) wrap around it.
1562+ final Finder wrapper = find.ancestor (
1563+ of: find.byKey (rootNavigatorKey),
1564+ matching: find.byWidgetPredicate (
1565+ (Widget widget) => widget is Semantics && widget.container,
1566+ ),
1567+ );
1568+ expect (wrapper, findsNothing);
1569+ });
1570+
1571+ testWidgets ('Chrome painted before a StatefulShellRoute Navigator stays in the '
1572+ 'semantics tree alongside routed content' , (WidgetTester tester) async {
1573+ final SemanticsHandle semantics = tester.ensureSemantics ();
1574+ StatefulNavigationShell ? navigationShell;
1575+
1576+ final router = GoRouter (
1577+ initialLocation: '/a' ,
1578+ routes: < RouteBase > [
1579+ StatefulShellRoute .indexedStack (
1580+ builder: (BuildContext context, GoRouterState state, StatefulNavigationShell shell) {
1581+ navigationShell = shell;
1582+ return Column (
1583+ children: < Widget > [
1584+ Semantics (container: true , label: 'chrome' , child: const SizedBox (height: 10 )),
1585+ Expanded (child: shell),
1586+ ],
1587+ );
1588+ },
1589+ branches: < StatefulShellBranch > [
1590+ StatefulShellBranch (
1591+ routes: < RouteBase > [
1592+ GoRoute (
1593+ path: '/a' ,
1594+ builder: (BuildContext context, GoRouterState state) {
1595+ return const Text ('content-a' );
1596+ },
1597+ ),
1598+ ],
1599+ ),
1600+ StatefulShellBranch (
1601+ routes: < RouteBase > [
1602+ GoRoute (
1603+ path: '/b' ,
1604+ builder: (BuildContext context, GoRouterState state) {
1605+ return const Text ('content-b' );
1606+ },
1607+ ),
1608+ ],
1609+ ),
1610+ ],
1611+ ),
1612+ ],
1613+ );
1614+ addTearDown (router.dispose);
1615+
1616+ await tester.pumpWidget (MaterialApp .router (routerConfig: router));
1617+ await tester.pumpAndSettle ();
1618+
1619+ // Without the Semantics(container: true) wrap around the shell
1620+ // branch's Navigator, the route's ModalBarrier (BlockSemantics)
1621+ // drops the chrome painted before it, because a Navigator does not
1622+ // establish a semantics boundary. See
1623+ // https://github.com/flutter/flutter/issues/135656.
1624+ expect (find.bySemanticsLabel ('chrome' ), findsOneWidget);
1625+ expect (find.bySemanticsLabel ('content-a' ), findsOneWidget);
1626+
1627+ // Switching branches keeps the chrome exposed after the rebuild.
1628+ navigationShell! .goBranch (1 );
1629+ await tester.pumpAndSettle ();
1630+
1631+ expect (find.bySemanticsLabel ('chrome' ), findsOneWidget);
1632+ expect (find.bySemanticsLabel ('content-b' ), findsOneWidget);
1633+ expect (find.bySemanticsLabel ('content-a' ), findsNothing);
1634+
1635+ semantics.dispose ();
1636+ });
1637+ });
14361638 });
14371639}
14381640
0 commit comments