Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
05854afa
Unverified
Commit
05854afa
authored
Jan 19, 2024
by
Qun Cheng
Committed by
GitHub
Jan 19, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`SearchAnchor` search view clear button only shows up when text input is not empty (#141755)
parent
684247a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
search_anchor.dart
packages/flutter/lib/src/material/search_anchor.dart
+1
-1
search_anchor_test.dart
packages/flutter/test/material/search_anchor_test.dart
+32
-5
No files found.
packages/flutter/lib/src/material/search_anchor.dart
View file @
05854afa
...
...
@@ -816,7 +816,7 @@ class _ViewContentState extends State<_ViewContent> {
);
final
List
<
Widget
>
defaultTrailing
=
<
Widget
>[
IconButton
(
if
(
_controller
.
text
.
isNotEmpty
)
IconButton
(
icon:
const
Icon
(
Icons
.
close
),
onPressed:
()
{
_controller
.
clear
();
...
...
packages/flutter/test/material/search_anchor_test.dart
View file @
05854afa
...
...
@@ -1140,10 +1140,6 @@ void main() {
// Default search view has a leading back button on the start of the header.
expect
(
find
.
widgetWithIcon
(
IconButton
,
Icons
.
arrow_back
),
findsOneWidget
);
// Default search view has a trailing close button on the end of the header.
// It is used to clear the input in the text field.
expect
(
find
.
widgetWithIcon
(
IconButton
,
Icons
.
close
),
findsOneWidget
);
final
Text
helperText
=
tester
.
widget
(
find
.
text
(
'hint text'
));
expect
(
helperText
.
style
?.
color
,
colorScheme
.
onSurfaceVariant
);
expect
(
helperText
.
style
?.
fontSize
,
16.0
);
...
...
@@ -1443,7 +1439,9 @@ void main() {
await
tester
.
pumpWidget
(
buildAnchor
());
await
tester
.
tap
(
find
.
widgetWithIcon
(
IconButton
,
Icons
.
search
));
await
tester
.
pumpAndSettle
();
// Default is a icon button with close icon.
// Default is a icon button with close icon when input is not empty.
await
tester
.
enterText
(
findTextField
(),
'a'
);
await
tester
.
pump
();
expect
(
find
.
widgetWithIcon
(
IconButton
,
Icons
.
close
),
findsOneWidget
);
await
tester
.
pumpWidget
(
Container
());
...
...
@@ -3062,6 +3060,35 @@ void main() {
final
RenderBox
box
=
tester
.
renderObject
(
findHeader
);
expect
(
box
.
size
.
height
,
32
);
});
testWidgets
(
'The default clear button only shows when text input is not empty '
'on the search view'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Center
(
child:
Material
(
child:
SearchAnchor
(
builder:
(
BuildContext
context
,
SearchController
controller
)
{
return
const
Icon
(
Icons
.
search
);
},
suggestionsBuilder:
(
BuildContext
context
,
SearchController
controller
)
{
return
<
Widget
>[];
},
),
),
),
));
await
tester
.
pump
();
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
search
));
// Open search view.
await
tester
.
pumpAndSettle
();
expect
(
find
.
widgetWithIcon
(
IconButton
,
Icons
.
close
),
findsNothing
);
await
tester
.
enterText
(
findTextField
(),
'a'
);
await
tester
.
pump
();
expect
(
find
.
widgetWithIcon
(
IconButton
,
Icons
.
close
),
findsOneWidget
);
await
tester
.
enterText
(
findTextField
(),
''
);
await
tester
.
pump
();
expect
(
find
.
widgetWithIcon
(
IconButton
,
Icons
.
close
),
findsNothing
);
});
}
Future
<
void
>
checkSearchBarDefaults
(
WidgetTester
tester
,
ColorScheme
colorScheme
,
Material
material
)
async
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment