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
257f5112
Unverified
Commit
257f5112
authored
Apr 13, 2021
by
xubaolin
Committed by
GitHub
Apr 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update SearchDelegate's leading and actions widgets can be null (#80006)
parent
5140376e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
2 deletions
+89
-2
search.dart
packages/flutter/lib/src/material/search.dart
+2
-2
search_test.dart
packages/flutter/test/material/search_test.dart
+87
-0
No files found.
packages/flutter/lib/src/material/search.dart
View file @
257f5112
...
...
@@ -180,7 +180,7 @@ abstract class SearchDelegate<T> {
/// See also:
///
/// * [AppBar.leading], the intended use for the return value of this method.
Widget
buildLeading
(
BuildContext
context
);
Widget
?
buildLeading
(
BuildContext
context
);
/// Widgets to display after the search query in the [AppBar].
///
...
...
@@ -193,7 +193,7 @@ abstract class SearchDelegate<T> {
/// See also:
///
/// * [AppBar.actions], the intended use for the return value of this method.
List
<
Widget
>
buildActions
(
BuildContext
context
);
List
<
Widget
>
?
buildActions
(
BuildContext
context
);
/// Widget to display across the bottom of the [AppBar].
///
...
...
packages/flutter/test/material/search_test.dart
View file @
257f5112
...
...
@@ -771,6 +771,48 @@ void main() {
expect
(
textField
.
style
!.
color
,
themeData
.
textTheme
.
bodyText1
!.
color
);
expect
(
textField
.
style
!.
color
,
isNot
(
equals
(
themeData
.
primaryColor
)));
});
// Regression test for: https://github.com/flutter/flutter/issues/78144
testWidgets
(
'`Leading` and `Actions` nullable test'
,
(
WidgetTester
tester
)
async
{
// The search delegate page is displayed with no issues
// even with a null return values for [buildLeading] and [buildActions].
final
_TestEmptySearchDelegate
delegate
=
_TestEmptySearchDelegate
(
result:
'Result'
,
suggestions:
'Suggestions'
,
);
final
List
<
String
>
selectedResults
=
<
String
>[];
await
tester
.
pumpWidget
(
TestHomePage
(
delegate:
delegate
,
results:
selectedResults
,
));
// We are on the homepage.
expect
(
find
.
text
(
'HomeBody'
),
findsOneWidget
);
expect
(
find
.
text
(
'HomeTitle'
),
findsOneWidget
);
expect
(
find
.
text
(
'Suggestions'
),
findsNothing
);
// Open the search page.
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'HomeBody'
),
findsNothing
);
expect
(
find
.
text
(
'HomeTitle'
),
findsNothing
);
expect
(
find
.
text
(
'Suggestions'
),
findsOneWidget
);
expect
(
selectedResults
,
hasLength
(
0
));
final
TextField
textField
=
tester
.
widget
(
find
.
byType
(
TextField
));
expect
(
textField
.
focusNode
!.
hasFocus
,
isTrue
);
// Close the search page.
await
tester
.
tap
(
find
.
byTooltip
(
'Close'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'HomeBody'
),
findsOneWidget
);
expect
(
find
.
text
(
'HomeTitle'
),
findsOneWidget
);
expect
(
find
.
text
(
'Suggestions'
),
findsNothing
);
expect
(
selectedResults
,
<
String
>[
'Result'
]);
});
}
class
TestHomePage
extends
StatelessWidget
{
...
...
@@ -911,3 +953,48 @@ class _TestSearchDelegate extends SearchDelegate<String> {
);
}
}
class
_TestEmptySearchDelegate
extends
SearchDelegate
<
String
>
{
_TestEmptySearchDelegate
({
this
.
suggestions
=
'Suggestions'
,
this
.
result
=
'Result'
,
})
:
super
();
final
String
suggestions
;
final
String
result
;
@override
Widget
?
buildLeading
(
BuildContext
context
)
=>
null
;
@override
List
<
Widget
>?
buildActions
(
BuildContext
context
)
=>
null
;
@override
Widget
buildSuggestions
(
BuildContext
context
)
{
return
MaterialButton
(
onPressed:
()
{
showResults
(
context
);
},
child:
Text
(
suggestions
),
);
}
@override
Widget
buildResults
(
BuildContext
context
)
{
return
const
Text
(
'Results'
);
}
@override
PreferredSizeWidget
buildBottom
(
BuildContext
context
)
{
return
PreferredSize
(
preferredSize:
const
Size
.
fromHeight
(
56.0
),
child:
IconButton
(
tooltip:
'Close'
,
icon:
const
Icon
(
Icons
.
arrow_back
),
onPressed:
()
{
close
(
context
,
result
);
},
),
);
}
}
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