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
a0b5448b
Unverified
Commit
a0b5448b
authored
6 years ago
by
Jonah Williams
Committed by
GitHub
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add route/routeName to search page (#20190)
parent
d1f446e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
23 deletions
+146
-23
search.dart
packages/flutter/lib/src/material/search.dart
+40
-23
search_test.dart
packages/flutter/test/material/search_test.dart
+106
-0
No files found.
packages/flutter/lib/src/material/search.dart
View file @
a0b5448b
...
...
@@ -4,6 +4,7 @@
import
'dart:async'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/widgets.dart'
;
import
'app_bar.dart'
;
...
...
@@ -389,6 +390,7 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
@override
Widget
build
(
BuildContext
context
)
{
final
ThemeData
theme
=
widget
.
delegate
.
appBarTheme
(
context
);
final
String
searchFieldLabel
=
MaterialLocalizations
.
of
(
context
).
searchFieldLabel
;
Widget
body
;
switch
(
widget
.
delegate
.
_currentBody
)
{
case
_SearchBody
.
suggestions
:
...
...
@@ -404,32 +406,47 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
);
break
;
}
String
routeName
;
switch
(
defaultTargetPlatform
)
{
case
TargetPlatform
.
iOS
:
routeName
=
''
;
break
;
case
TargetPlatform
.
android
:
case
TargetPlatform
.
fuchsia
:
routeName
=
searchFieldLabel
;
}
return
new
Scaffold
(
appBar:
new
AppBar
(
backgroundColor:
theme
.
primaryColor
,
iconTheme:
theme
.
primaryIconTheme
,
textTheme:
theme
.
primaryTextTheme
,
brightness:
theme
.
primaryColorBrightness
,
leading:
widget
.
delegate
.
buildLeading
(
context
),
title:
new
TextField
(
controller:
queryTextController
,
focusNode:
widget
.
delegate
.
_focusNode
,
style:
theme
.
textTheme
.
title
,
textInputAction:
TextInputAction
.
search
,
onSubmitted:
(
String
_
)
{
widget
.
delegate
.
showResults
(
context
);
},
decoration:
new
InputDecoration
(
border:
InputBorder
.
none
,
hintText:
MaterialLocalizations
.
of
(
context
).
searchFieldLabel
,
return
new
Semantics
(
explicitChildNodes:
true
,
scopesRoute:
true
,
namesRoute:
true
,
label:
routeName
,
child:
new
Scaffold
(
appBar:
new
AppBar
(
backgroundColor:
theme
.
primaryColor
,
iconTheme:
theme
.
primaryIconTheme
,
textTheme:
theme
.
primaryTextTheme
,
brightness:
theme
.
primaryColorBrightness
,
leading:
widget
.
delegate
.
buildLeading
(
context
),
title:
new
TextField
(
controller:
queryTextController
,
focusNode:
widget
.
delegate
.
_focusNode
,
style:
theme
.
textTheme
.
title
,
textInputAction:
TextInputAction
.
search
,
onSubmitted:
(
String
_
)
{
widget
.
delegate
.
showResults
(
context
);
},
decoration:
new
InputDecoration
(
border:
InputBorder
.
none
,
hintText:
searchFieldLabel
,
),
),
actions:
widget
.
delegate
.
buildActions
(
context
),
),
body:
new
AnimatedSwitcher
(
duration:
const
Duration
(
milliseconds:
300
),
child:
body
,
),
actions:
widget
.
delegate
.
buildActions
(
context
),
),
body:
new
AnimatedSwitcher
(
duration:
const
Duration
(
milliseconds:
300
),
child:
body
,
),
);
}
...
...
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/search_test.dart
View file @
a0b5448b
...
...
@@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'../widgets/semantics_tester.dart'
;
void
main
(
)
{
testWidgets
(
'Can open and close search'
,
(
WidgetTester
tester
)
async
{
final
_TestSearchDelegate
delegate
=
new
_TestSearchDelegate
();
...
...
@@ -477,6 +480,109 @@ void main() {
expect
(
tester
.
testTextInput
.
setClientArgs
[
'inputAction'
],
TextInputAction
.
search
.
toString
());
});
group
(
'contributes semantics'
,
()
{
TestSemantics
buildExpected
({
String
routeName
})
{
return
new
TestSemantics
.
root
(
children:
<
TestSemantics
>[
new
TestSemantics
(
id:
1
,
textDirection:
TextDirection
.
ltr
,
children:
<
TestSemantics
>[
new
TestSemantics
(
id:
7
,
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
scopesRoute
,
SemanticsFlag
.
namesRoute
,
],
label:
routeName
,
textDirection:
TextDirection
.
ltr
,
children:
<
TestSemantics
>[
new
TestSemantics
(
id:
8
,
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isButton
,
SemanticsFlag
.
hasEnabledState
,
SemanticsFlag
.
isEnabled
,
],
actions:
<
SemanticsAction
>[
SemanticsAction
.
tap
],
label:
'Suggestions'
,
textDirection:
TextDirection
.
ltr
,
),
new
TestSemantics
(
id:
9
,
children:
<
TestSemantics
>[
new
TestSemantics
(
id:
10
,
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isButton
,
SemanticsFlag
.
hasEnabledState
,
SemanticsFlag
.
isEnabled
,
],
actions:
<
SemanticsAction
>[
SemanticsAction
.
tap
],
label:
'Back'
,
textDirection:
TextDirection
.
ltr
,
),
new
TestSemantics
(
id:
11
,
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isTextField
,
SemanticsFlag
.
isFocused
,
SemanticsFlag
.
isHeader
,
SemanticsFlag
.
namesRoute
,
],
actions:
<
SemanticsAction
>[
SemanticsAction
.
tap
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
paste
,
],
label:
'Search'
,
textDirection:
TextDirection
.
ltr
,
),
],
),
],
),
],
),
],
);
}
testWidgets
(
'includes routeName on Android'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
new
SemanticsTester
(
tester
);
final
_TestSearchDelegate
delegate
=
new
_TestSearchDelegate
();
await
tester
.
pumpWidget
(
new
TestHomePage
(
delegate:
delegate
,
));
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pumpAndSettle
();
expect
(
semantics
,
hasSemantics
(
buildExpected
(
routeName:
'Search'
),
ignoreId:
true
,
ignoreRect:
true
,
ignoreTransform:
true
));
semantics
.
dispose
();
});
testWidgets
(
'does not include routeName on iOS'
,
(
WidgetTester
tester
)
async
{
debugDefaultTargetPlatformOverride
=
TargetPlatform
.
iOS
;
final
SemanticsTester
semantics
=
new
SemanticsTester
(
tester
);
final
_TestSearchDelegate
delegate
=
new
_TestSearchDelegate
();
await
tester
.
pumpWidget
(
new
TestHomePage
(
delegate:
delegate
,
));
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pumpAndSettle
();
expect
(
semantics
,
hasSemantics
(
buildExpected
(
routeName:
''
),
ignoreId:
true
,
ignoreRect:
true
,
ignoreTransform:
true
));
debugDefaultTargetPlatformOverride
=
null
;
semantics
.
dispose
();
});
});
}
class
TestHomePage
extends
StatelessWidget
{
...
...
This diff is collapsed.
Click to expand it.
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