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
69d76377
Unverified
Commit
69d76377
authored
Oct 29, 2020
by
Darren Austin
Committed by
GitHub
Oct 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Updated SearchDelegate to follow custom InputDecorationTheme (#55209)" (#69241)
parent
68a87ee7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
96 deletions
+52
-96
search.dart
packages/flutter/lib/src/material/search.dart
+32
-43
search_test.dart
packages/flutter/test/material/search_test.dart
+20
-53
No files found.
packages/flutter/lib/src/material/search.dart
View file @
69d76377
...
...
@@ -92,10 +92,9 @@ Future<T?> showSearch<T>({
/// ## Handling emojis and other complex characters
/// {@macro flutter.widgets.editableText.complexCharacters}
abstract
class
SearchDelegate
<
T
>
{
/// Constructor to be called by subclasses which may specify
/// [searchFieldLabel], either [searchFieldStyle] or [searchFieldDecorationTheme],
/// [keyboardType] and/or [textInputAction]. Only one of [searchFieldLabel]
/// and [searchFieldDecorationTheme] may be non-null.
/// Constructor to be called by subclasses which may specify [searchFieldLabel], [keyboardType] and/or
/// [textInputAction].
///
/// {@tool snippet}
/// ```dart
...
...
@@ -125,10 +124,9 @@ abstract class SearchDelegate<T> {
SearchDelegate
({
this
.
searchFieldLabel
,
this
.
searchFieldStyle
,
this
.
searchFieldDecorationTheme
,
this
.
keyboardType
,
this
.
textInputAction
=
TextInputAction
.
search
,
})
:
assert
(
searchFieldStyle
==
null
||
searchFieldDecorationTheme
==
null
)
;
});
/// Suggestions shown in the body of the search page while the user types a
/// query into the search field.
...
...
@@ -207,11 +205,6 @@ abstract class SearchDelegate<T> {
primaryIconTheme:
theme
.
primaryIconTheme
.
copyWith
(
color:
Colors
.
grey
),
primaryColorBrightness:
Brightness
.
light
,
primaryTextTheme:
theme
.
textTheme
,
inputDecorationTheme:
searchFieldDecorationTheme
??
InputDecorationTheme
(
hintStyle:
searchFieldStyle
??
theme
.
inputDecorationTheme
.
hintStyle
,
border:
InputBorder
.
none
,
),
);
}
...
...
@@ -283,18 +276,8 @@ abstract class SearchDelegate<T> {
///
/// If this value is set to null, the value of the ambient [Theme]'s
/// [InputDecorationTheme.hintStyle] will be used instead.
///
/// If this value is not null, [searchFieldDecorationTheme]
/// will be ignored so this can be used.
final
TextStyle
?
searchFieldStyle
;
/// The [InputDecorationTheme] for the search field, use
/// this if you just want to customize the [TextField]
///
/// If this value is not null, [searchFieldStyle]
/// will be ignored so this can be used.
final
InputDecorationTheme
?
searchFieldDecorationTheme
;
/// The type of action button to use for the keyboard.
///
/// Defaults to the default value specified in [TextField].
...
...
@@ -499,6 +482,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
final
ThemeData
theme
=
widget
.
delegate
.
appBarTheme
(
context
);
final
String
searchFieldLabel
=
widget
.
delegate
.
searchFieldLabel
??
MaterialLocalizations
.
of
(
context
).
searchFieldLabel
;
final
TextStyle
?
searchFieldStyle
=
widget
.
delegate
.
searchFieldStyle
??
theme
.
inputDecorationTheme
.
hintStyle
;
Widget
?
body
;
switch
(
widget
.
delegate
.
_currentBody
)
{
case
_SearchBody
.
suggestions
:
...
...
@@ -516,8 +501,7 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
case
null
:
break
;
}
late
final
String
routeName
;
final
String
routeName
;
switch
(
theme
.
platform
)
{
case
TargetPlatform
.
iOS
:
case
TargetPlatform
.
macOS
:
...
...
@@ -535,28 +519,33 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
scopesRoute:
true
,
namesRoute:
true
,
label:
routeName
,
child:
Theme
(
data:
theme
,
child:
Scaffold
(
appBar:
AppBar
(
leading:
widget
.
delegate
.
buildLeading
(
context
),
title:
TextField
(
controller:
widget
.
delegate
.
_queryTextController
,
focusNode:
focusNode
,
style:
theme
.
textTheme
.
title
,
textInputAction:
widget
.
delegate
.
textInputAction
,
keyboardType:
widget
.
delegate
.
keyboardType
,
onSubmitted:
(
String
_
)
{
widget
.
delegate
.
showResults
(
context
);
},
decoration:
InputDecoration
(
hintText:
searchFieldLabel
),
child:
Scaffold
(
appBar:
AppBar
(
backgroundColor:
theme
.
primaryColor
,
iconTheme:
theme
.
primaryIconTheme
,
textTheme:
theme
.
primaryTextTheme
,
brightness:
theme
.
primaryColorBrightness
,
leading:
widget
.
delegate
.
buildLeading
(
context
),
title:
TextField
(
controller:
widget
.
delegate
.
_queryTextController
,
focusNode:
focusNode
,
style:
theme
.
textTheme
.
headline6
,
textInputAction:
widget
.
delegate
.
textInputAction
,
keyboardType:
widget
.
delegate
.
keyboardType
,
onSubmitted:
(
String
_
)
{
widget
.
delegate
.
showResults
(
context
);
},
decoration:
InputDecoration
(
border:
InputBorder
.
none
,
hintText:
searchFieldLabel
,
hintStyle:
searchFieldStyle
,
),
actions:
widget
.
delegate
.
buildActions
(
context
),
),
body:
AnimatedSwitcher
(
duration:
const
Duration
(
milliseconds:
300
),
child:
body
,
),
actions:
widget
.
delegate
.
buildActions
(
context
),
),
body:
AnimatedSwitcher
(
duration:
const
Duration
(
milliseconds:
300
),
child:
body
,
),
),
);
...
...
packages/flutter/test/material/search_test.dart
View file @
69d76377
...
...
@@ -122,8 +122,7 @@ void main() {
});
testWidgets
(
'Hint text color overridden'
,
(
WidgetTester
tester
)
async
{
const
String
searchHintText
=
'Enter search terms'
;
final
_TestSearchDelegate
delegate
=
_TestSearchDelegate
(
searchHint:
searchHintText
);
final
_TestSearchDelegate
delegate
=
_TestSearchDelegate
();
await
tester
.
pumpWidget
(
TestHomePage
(
delegate:
delegate
,
...
...
@@ -131,8 +130,9 @@ void main() {
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pumpAndSettle
();
final
Text
hintText
=
tester
.
widget
(
find
.
text
(
searchHintText
));
expect
(
hintText
.
style
!.
color
,
_TestSearchDelegate
.
hintTextColor
);
final
TextField
textField
=
tester
.
widget
<
TextField
>(
find
.
byType
(
TextField
));
final
Color
hintColor
=
textField
.
decoration
!.
hintStyle
!.
color
!;
expect
(
hintColor
,
delegate
.
hintTextColor
);
});
testWidgets
(
'Requests suggestions'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -540,18 +540,20 @@ void main() {
});
testWidgets
(
'Custom searchFieldStyle value'
,
(
WidgetTester
tester
)
async
{
const
String
searchHintText
=
'Enter search terms'
;
const
TextStyle
searchFieldStyle
=
TextStyle
(
color:
Colors
.
red
,
fontSize:
3
);
const
TextStyle
searchStyle
=
TextStyle
(
color:
Colors
.
red
,
fontSize:
3
);
final
_TestSearchDelegate
delegate
=
_TestSearchDelegate
(
search
Hint:
searchHintText
,
searchFieldStyle:
searchField
Style
);
final
_TestSearchDelegate
delegate
=
_TestSearchDelegate
(
search
FieldStyle:
search
Style
);
await
tester
.
pumpWidget
(
TestHomePage
(
delegate:
delegate
));
await
tester
.
pumpWidget
(
TestHomePage
(
delegate:
delegate
,
));
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pumpAndSettle
();
final
Text
hintText
=
tester
.
widget
(
find
.
text
(
searchHintText
));
expect
(
hintText
.
style
?.
color
,
delegate
.
searchFieldStyle
?.
color
)
;
expect
(
hint
Text
.
style
?.
fontSize
,
delegate
.
searchFieldStyle
?.
fontSiz
e
);
final
Text
Field
textField
=
tester
.
widget
<
TextField
>(
find
.
byType
(
TextField
));
final
TextStyle
hintStyle
=
textField
.
decoration
!.
hintStyle
!
;
expect
(
hint
Style
,
delegate
.
searchFieldStyl
e
);
});
testWidgets
(
'keyboard show search button by default'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -690,23 +692,6 @@ void main() {
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
});
testWidgets
(
'Custom searchFieldDecorationTheme value'
,
(
WidgetTester
tester
)
async
{
const
InputDecorationTheme
searchFieldDecorationTheme
=
InputDecorationTheme
(
hintStyle:
TextStyle
(
color:
_TestSearchDelegate
.
hintTextColor
),
);
final
_TestSearchDelegate
delegate
=
_TestSearchDelegate
(
searchFieldDecorationTheme:
searchFieldDecorationTheme
,
);
await
tester
.
pumpWidget
(
TestHomePage
(
delegate:
delegate
));
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pumpAndSettle
();
final
ThemeData
?
textFieldTheme
=
Theme
.
of
(
tester
.
element
(
find
.
byType
(
TextField
)));
expect
(
textFieldTheme
?.
inputDecorationTheme
,
searchFieldDecorationTheme
);
});
// Regression test for: https://github.com/flutter/flutter/issues/66781
testWidgets
(
'text in search bar contrasts background (light mode)'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
themeData
=
ThemeData
.
light
();
...
...
@@ -724,11 +709,8 @@ void main() {
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pumpAndSettle
();
final
Material
appBarBackground
=
tester
.
widget
<
Material
>(
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
),
));
expect
(
appBarBackground
.
color
,
Colors
.
white
);
final
AppBar
appBar
=
tester
.
widget
<
AppBar
>(
find
.
byType
(
AppBar
));
expect
(
appBar
.
backgroundColor
,
Colors
.
white
);
final
TextField
textField
=
tester
.
widget
<
TextField
>(
find
.
byType
(
TextField
));
expect
(
textField
.
style
!.
color
,
themeData
.
textTheme
.
bodyText1
!.
color
);
...
...
@@ -752,11 +734,8 @@ void main() {
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pumpAndSettle
();
final
Material
appBarBackground
=
tester
.
widget
<
Material
>(
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
),
));
expect
(
appBarBackground
.
color
,
themeData
.
primaryColor
);
final
AppBar
appBar
=
tester
.
widget
<
AppBar
>(
find
.
byType
(
AppBar
));
expect
(
appBar
.
backgroundColor
,
themeData
.
primaryColor
);
final
TextField
textField
=
tester
.
widget
<
TextField
>(
find
.
byType
(
TextField
));
expect
(
textField
.
style
!.
color
,
themeData
.
textTheme
.
bodyText1
!.
color
);
...
...
@@ -824,22 +803,16 @@ class _TestSearchDelegate extends SearchDelegate<String> {
this
.
result
=
'Result'
,
this
.
actions
=
const
<
Widget
>[],
this
.
defaultAppBarTheme
=
false
,
InputDecorationTheme
?
searchFieldDecorationTheme
,
TextStyle
?
searchFieldStyle
,
String
?
searchHint
,
TextInputAction
textInputAction
=
TextInputAction
.
search
,
})
:
super
(
searchFieldLabel:
searchHint
,
textInputAction:
textInputAction
,
searchFieldStyle:
searchFieldStyle
,
searchFieldDecorationTheme:
searchFieldDecorationTheme
,
);
})
:
super
(
searchFieldLabel:
searchHint
,
textInputAction:
textInputAction
,
searchFieldStyle:
searchFieldStyle
);
final
bool
defaultAppBarTheme
;
final
String
suggestions
;
final
String
result
;
final
List
<
Widget
>
actions
;
static
const
Color
hintTextColor
=
Colors
.
green
;
final
Color
hintTextColor
=
Colors
.
green
;
@override
ThemeData
appBarTheme
(
BuildContext
context
)
{
...
...
@@ -848,13 +821,7 @@ class _TestSearchDelegate extends SearchDelegate<String> {
}
final
ThemeData
theme
=
Theme
.
of
(
context
)!;
return
theme
.
copyWith
(
inputDecorationTheme:
searchFieldDecorationTheme
??
InputDecorationTheme
(
hintStyle:
searchFieldStyle
??
const
TextStyle
(
color:
hintTextColor
,
),
),
inputDecorationTheme:
InputDecorationTheme
(
hintStyle:
TextStyle
(
color:
hintTextColor
)),
);
}
...
...
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