Search view expands to full screen on device rotation#186537
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the SearchAnchor component to ensure the search view correctly adapts to screen rotation by removing the viewMaxWidth parameter and utilizing a LayoutBuilder for dynamic constraints. It also includes a new regression test to verify full-screen expansion. Review feedback suggests that the LayoutBuilder is redundant because the view's dimensions are already updated via existing lifecycle methods, and recommends simplifying the widget tree and constraint logic to enhance readability and performance.
|
Note: Review with "hide whitespace" 😄 |
|
I believe Please check if this example (dynamically changing navigator height) works well with proposed changes: test.dartimport 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() => runApp(const DraggableScrollableSheetExampleApp());
class DraggableScrollableSheetExampleApp extends StatelessWidget {
const DraggableScrollableSheetExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue.shade100),
),
home: Scaffold(
appBar: AppBar(title: const Text('DraggableScrollableSheet Sample')),
body: const DraggableScrollableSheetExample(),
),
);
}
}
class DraggableScrollableSheetExample extends StatefulWidget {
const DraggableScrollableSheetExample({super.key});
@override
State<DraggableScrollableSheetExample> createState() =>
_DraggableScrollableSheetExampleState();
}
class _DraggableScrollableSheetExampleState
extends State<DraggableScrollableSheetExample> {
double _dragPosition = 0.5;
late double _sheetPosition = _dragPosition;
final minChildSize = 0.25;
final maxChildSize = 1.0;
@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final double viewHeight = constraints.maxHeight;
return DraggableScrollableSheet(
initialChildSize: _sheetPosition,
builder: (BuildContext context, ScrollController scrollController) {
return ColoredBox(
color: colorScheme.primary,
child: Column(
children: <Widget>[
if (_isOnDesktopAndWeb)
Grabber(
onVerticalDragUpdate: (DragUpdateDetails details) {
setState(() {
_dragPosition -= details.delta.dy / viewHeight;
_sheetPosition = _dragPosition.clamp(
minChildSize,
maxChildSize,
);
});
},
),
Flexible(
child: Navigator(
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => Scaffold(
body: SearchAnchor.bar(
isFullScreen: true,
suggestionsBuilder: (context, controller) => [
for (var i = 0; i < 10; i++)
ListTile(title: Text('Test $i')),
],
),
),
),
),
),
],
),
);
},
);
},
);
}
bool get _isOnDesktopAndWeb =>
kIsWeb ||
switch (defaultTargetPlatform) {
TargetPlatform.macOS ||
TargetPlatform.linux ||
TargetPlatform.windows => true,
TargetPlatform.android ||
TargetPlatform.iOS ||
TargetPlatform.fuchsia => false,
};
}
class Grabber extends StatelessWidget {
const Grabber({super.key, required this.onVerticalDragUpdate});
final ValueChanged<DragUpdateDetails> onVerticalDragUpdate;
@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
return GestureDetector(
onVerticalDragUpdate: onVerticalDragUpdate,
child: Container(
width: double.infinity,
color: colorScheme.onSurface,
child: Align(
alignment: Alignment.topCenter,
child: Container(
margin: const EdgeInsets.symmetric(vertical: 8.0),
width: 32.0,
height: 4.0,
decoration: BoxDecoration(
color: colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8.0),
),
),
),
),
);
}
} |
|
Hi @Zekfad - that sounds like a different issue than what this PR is addressing. Please file an issue for the above so that it can be tracked. Thanks! |
45eaacb to
0399dca
Compare
|
Thank you for your reply. Should we unlink this PR from #186154, or should I file separate issue anyway, maybe then we need to clarify 186154? |
I think we also fix the window resizing. This is the example you provdied. Screen.Recording.2026-05-18.at.12.27.29.PM.mov |
|
With the latest commit, the code sample in #186537 (comment) should also be working correctly.
|
|
@QuncCccccc, @elliette thank you very much for your time to provide demo videos and fix for the edge case as well! |
| child: ConstrainedBox( | ||
| constraints: BoxConstraints( | ||
| minWidth: minWidth, | ||
| maxWidth: widget.showFullScreenView |
ba10bb8 to
aba3d45
Compare
|
Seems this PR is ready to go🥳! Since we are waiting for decoupling, I added a "waiting for code freeze" label above and converted this PR to draft so later we'll move the change to |

Fixes #186154
The search anchor overlay now expands to fill the entire screen when the device is rotated and
isFullScreenis true.For non-mobile devices, the open search anchor overlay is similarly resized when the the device size is changed.
Previously we were calculating the search view's max width whenever the search view's route was pushed/popped. Switched to using the constraints provided by
LayoutBuilderso that we can recalculate the view's max width during the layout phase when the device is rotated.Before
After
Pre-launch Checklist
///).