Unverified Commit f31dae2a authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Clip search view content during animation (#126975)

Fixes #126590

This PR is to clip the view content when the view size is not big enough, such as during animation.
Also removes some unused properties in `_ViewContent` class: `getRect` and `viewConstraints`
parent 8089a309
......@@ -579,11 +579,10 @@ class _SearchViewRoute extends PopupRoute<_SearchViewRoute> {
viewHeaderTextStyle: viewHeaderTextStyle,
viewHeaderHintStyle: viewHeaderHintStyle,
dividerColor: dividerColor,
viewConstraints: viewConstraints,
showFullScreenView: showFullScreenView,
animation: curvedAnimation,
getRect: getRect,
topPadding: topPadding,
viewMaxWidth: _rectTween.end!.width,
viewRect: viewRect,
viewDefaults: viewDefaults,
viewTheme: viewTheme,
......@@ -616,11 +615,10 @@ class _ViewContent extends StatefulWidget {
this.viewHeaderTextStyle,
this.viewHeaderHintStyle,
this.dividerColor,
this.viewConstraints,
required this.showFullScreenView,
required this.getRect,
required this.topPadding,
required this.animation,
required this.viewMaxWidth,
required this.viewRect,
required this.viewDefaults,
required this.viewTheme,
......@@ -641,11 +639,10 @@ class _ViewContent extends StatefulWidget {
final TextStyle? viewHeaderTextStyle;
final TextStyle? viewHeaderHintStyle;
final Color? dividerColor;
final BoxConstraints? viewConstraints;
final bool showFullScreenView;
final ValueGetter<Rect?> getRect;
final double topPadding;
final Animation<double> animation;
final double viewMaxWidth;
final Rect viewRect;
final SearchViewThemeData viewDefaults;
final SearchViewThemeData viewTheme;
......@@ -690,11 +687,13 @@ class _ViewContentState extends State<_ViewContent> {
result = widget.suggestionsBuilder(context, _controller);
final Size updatedScreenSize = MediaQuery.of(context).size;
if (_screenSize != updatedScreenSize && widget.showFullScreenView) {
if (_screenSize != updatedScreenSize) {
_screenSize = updatedScreenSize;
if (widget.showFullScreenView) {
_viewRect = Offset.zero & _screenSize!;
}
}
}
Widget viewBuilder(Iterable<Widget> suggestions) {
if (widget.viewBuilder == null) {
......@@ -782,6 +781,12 @@ class _ViewContentState extends State<_ViewContent> {
color: effectiveBackgroundColor,
surfaceTintColor: effectiveSurfaceTint,
elevation: effectiveElevation,
child: ClipRect(
clipBehavior: Clip.antiAlias,
child: OverflowBox(
alignment: Alignment.topLeft,
maxWidth: math.min(widget.viewMaxWidth, _screenSize!.width),
minWidth: 0,
child: FadeTransition(
opacity: CurvedAnimation(
parent: widget.animation,
......@@ -837,6 +842,8 @@ class _ViewContentState extends State<_ViewContent> {
),
),
),
),
),
);
}
}
......
......@@ -1639,6 +1639,46 @@ void main() {
await tester.pumpAndSettle();
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
});
testWidgets('Search view route does not throw exception during pop animation', (WidgetTester tester) async {
// regression test for https://github.com/flutter/flutter/issues/126590.
await tester.pumpWidget(MaterialApp(
home: Material(
child: Center(
child: SearchAnchor(
builder: (BuildContext context, SearchController controller) {
return IconButton(
icon: const Icon(Icons.search),
onPressed: () {
controller.openView();
},
);
},
suggestionsBuilder: (BuildContext context, SearchController controller) {
return List<Widget>.generate(5, (int index) {
final String item = 'item $index';
return ListTile(
leading: const Icon(Icons.history),
title: Text(item),
trailing: const Icon(Icons.chevron_right),
onTap: () {},
);
});
}),
),
),
));
// Open search view
await tester.tap(find.byIcon(Icons.search));
await tester.pumpAndSettle();
// Pop search view route
await tester.tap(find.byIcon(Icons.arrow_back));
await tester.pumpAndSettle();
// No exception.
});
}
TextStyle? _iconStyle(WidgetTester tester, IconData icon) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment