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> { ...@@ -579,11 +579,10 @@ class _SearchViewRoute extends PopupRoute<_SearchViewRoute> {
viewHeaderTextStyle: viewHeaderTextStyle, viewHeaderTextStyle: viewHeaderTextStyle,
viewHeaderHintStyle: viewHeaderHintStyle, viewHeaderHintStyle: viewHeaderHintStyle,
dividerColor: dividerColor, dividerColor: dividerColor,
viewConstraints: viewConstraints,
showFullScreenView: showFullScreenView, showFullScreenView: showFullScreenView,
animation: curvedAnimation, animation: curvedAnimation,
getRect: getRect,
topPadding: topPadding, topPadding: topPadding,
viewMaxWidth: _rectTween.end!.width,
viewRect: viewRect, viewRect: viewRect,
viewDefaults: viewDefaults, viewDefaults: viewDefaults,
viewTheme: viewTheme, viewTheme: viewTheme,
...@@ -616,11 +615,10 @@ class _ViewContent extends StatefulWidget { ...@@ -616,11 +615,10 @@ class _ViewContent extends StatefulWidget {
this.viewHeaderTextStyle, this.viewHeaderTextStyle,
this.viewHeaderHintStyle, this.viewHeaderHintStyle,
this.dividerColor, this.dividerColor,
this.viewConstraints,
required this.showFullScreenView, required this.showFullScreenView,
required this.getRect,
required this.topPadding, required this.topPadding,
required this.animation, required this.animation,
required this.viewMaxWidth,
required this.viewRect, required this.viewRect,
required this.viewDefaults, required this.viewDefaults,
required this.viewTheme, required this.viewTheme,
...@@ -641,11 +639,10 @@ class _ViewContent extends StatefulWidget { ...@@ -641,11 +639,10 @@ class _ViewContent extends StatefulWidget {
final TextStyle? viewHeaderTextStyle; final TextStyle? viewHeaderTextStyle;
final TextStyle? viewHeaderHintStyle; final TextStyle? viewHeaderHintStyle;
final Color? dividerColor; final Color? dividerColor;
final BoxConstraints? viewConstraints;
final bool showFullScreenView; final bool showFullScreenView;
final ValueGetter<Rect?> getRect;
final double topPadding; final double topPadding;
final Animation<double> animation; final Animation<double> animation;
final double viewMaxWidth;
final Rect viewRect; final Rect viewRect;
final SearchViewThemeData viewDefaults; final SearchViewThemeData viewDefaults;
final SearchViewThemeData viewTheme; final SearchViewThemeData viewTheme;
...@@ -690,11 +687,13 @@ class _ViewContentState extends State<_ViewContent> { ...@@ -690,11 +687,13 @@ class _ViewContentState extends State<_ViewContent> {
result = widget.suggestionsBuilder(context, _controller); result = widget.suggestionsBuilder(context, _controller);
final Size updatedScreenSize = MediaQuery.of(context).size; final Size updatedScreenSize = MediaQuery.of(context).size;
if (_screenSize != updatedScreenSize && widget.showFullScreenView) { if (_screenSize != updatedScreenSize) {
_screenSize = updatedScreenSize; _screenSize = updatedScreenSize;
if (widget.showFullScreenView) {
_viewRect = Offset.zero & _screenSize!; _viewRect = Offset.zero & _screenSize!;
} }
} }
}
Widget viewBuilder(Iterable<Widget> suggestions) { Widget viewBuilder(Iterable<Widget> suggestions) {
if (widget.viewBuilder == null) { if (widget.viewBuilder == null) {
...@@ -782,6 +781,12 @@ class _ViewContentState extends State<_ViewContent> { ...@@ -782,6 +781,12 @@ class _ViewContentState extends State<_ViewContent> {
color: effectiveBackgroundColor, color: effectiveBackgroundColor,
surfaceTintColor: effectiveSurfaceTint, surfaceTintColor: effectiveSurfaceTint,
elevation: effectiveElevation, elevation: effectiveElevation,
child: ClipRect(
clipBehavior: Clip.antiAlias,
child: OverflowBox(
alignment: Alignment.topLeft,
maxWidth: math.min(widget.viewMaxWidth, _screenSize!.width),
minWidth: 0,
child: FadeTransition( child: FadeTransition(
opacity: CurvedAnimation( opacity: CurvedAnimation(
parent: widget.animation, parent: widget.animation,
...@@ -837,6 +842,8 @@ class _ViewContentState extends State<_ViewContent> { ...@@ -837,6 +842,8 @@ class _ViewContentState extends State<_ViewContent> {
), ),
), ),
), ),
),
),
); );
} }
} }
......
...@@ -1639,6 +1639,46 @@ void main() { ...@@ -1639,6 +1639,46 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byIcon(Icons.arrow_back), findsOneWidget); 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) { 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