Skip to content

Commit 39bf968

Browse files
authored
fix: SearchAnchor View not resizing when in nested navigator (#128357)
Similar to what was done on flutter/flutter#127198, look for the closest navigator instead of screen size. Fixes: flutter/flutter#128344
1 parent d99e5fd commit 39bf968

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

packages/flutter/lib/src/material/search_anchor.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ class _SearchViewRoute extends PopupRoute<_SearchViewRoute> {
489489
}
490490

491491
void updateTweens(BuildContext context) {
492-
final Size screenSize = MediaQuery.of(context).size;
492+
final RenderBox navigator = Navigator.of(context).context.findRenderObject()! as RenderBox;
493+
final Size screenSize = navigator.size;
493494
final Rect anchorRect = getRect() ?? Rect.zero;
494495

495496
final BoxConstraints effectiveConstraints = viewConstraints ?? viewTheme.constraints ?? viewDefaults.constraints!;

packages/flutter/test/material/search_anchor_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,50 @@ void main() {
17891789
expect(searchViewRect.topLeft, equals(const Offset(rootSpacing, rootSpacing)));
17901790
});
17911791

1792+
testWidgets('Docked search view with nested navigator does not go off the screen', (WidgetTester tester) async {
1793+
addTearDown(tester.view.reset);
1794+
tester.view.physicalSize = const Size(400.0, 400.0);
1795+
tester.view.devicePixelRatio = 1.0;
1796+
1797+
const double rootSpacing = 100.0;
1798+
1799+
await tester.pumpWidget(MaterialApp(
1800+
builder: (BuildContext context, Widget? child) {
1801+
return Scaffold(
1802+
body: Padding(
1803+
padding: const EdgeInsets.all(rootSpacing),
1804+
child: child,
1805+
),
1806+
);
1807+
},
1808+
home: Material(
1809+
child: Align(
1810+
alignment: Alignment.bottomRight,
1811+
child: SearchAnchor(
1812+
isFullScreen: false,
1813+
builder: (BuildContext context, SearchController controller) {
1814+
return IconButton(
1815+
icon: const Icon(Icons.search),
1816+
onPressed: () {
1817+
controller.openView();
1818+
},
1819+
);
1820+
},
1821+
suggestionsBuilder: (BuildContext context, SearchController controller) {
1822+
return <Widget>[];
1823+
},
1824+
),
1825+
),
1826+
),
1827+
));
1828+
1829+
await tester.tap(find.byIcon(Icons.search));
1830+
await tester.pumpAndSettle();
1831+
1832+
final Rect searchViewRect = tester.getRect(find.descendant(of: findViewContent(), matching: find.byType(SizedBox)).first);
1833+
expect(searchViewRect.bottomRight, equals(const Offset(300.0, 300.0)));
1834+
});
1835+
17921836

17931837
// Regression tests for https://github.com/flutter/flutter/issues/126623
17941838
group('Overall InputDecorationTheme does not impact SearchBar and SearchView', () {

0 commit comments

Comments
 (0)