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
44ebcb66
Unverified
Commit
44ebcb66
authored
Jun 05, 2021
by
Bikram Pandit
Committed by
GitHub
Jun 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move cursor position to the end of search query in SearchDelegate after query is set (#83512)
parent
921c724d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
search.dart
packages/flutter/lib/src/material/search.dart
+5
-0
search_test.dart
packages/flutter/test/material/search_test.dart
+21
-0
No files found.
packages/flutter/lib/src/material/search.dart
View file @
44ebcb66
...
...
@@ -248,9 +248,14 @@ abstract class SearchDelegate<T> {
/// If the user taps on a suggestion provided by [buildSuggestions] this
/// string should be updated to that suggestion via the setter.
String
get
query
=>
_queryTextController
.
text
;
/// Changes the current query string.
///
/// Setting the query string programmatically moves the cursor to the end of the text field.
set
query
(
String
value
)
{
assert
(
query
!=
null
);
_queryTextController
.
text
=
value
;
_queryTextController
.
selection
=
TextSelection
.
fromPosition
(
TextPosition
(
offset:
_queryTextController
.
text
.
length
));
}
/// Transition from the suggestions returned by [buildSuggestions] to the
...
...
packages/flutter/test/material/search_test.dart
View file @
44ebcb66
...
...
@@ -40,6 +40,27 @@ void main() {
TestDefaultBinaryMessengerBinding
.
instance
!.
defaultBinaryMessenger
.
setMockMethodCallHandler
(
SystemChannels
.
platform
,
null
);
});
testWidgets
(
'Changing query moves cursor to the end of query'
,
(
WidgetTester
tester
)
async
{
final
_TestSearchDelegate
delegate
=
_TestSearchDelegate
();
await
tester
.
pumpWidget
(
TestHomePage
(
delegate:
delegate
));
await
tester
.
tap
(
find
.
byTooltip
(
'Search'
));
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
300
));
delegate
.
query
=
'Foo'
;
final
TextField
textField
=
tester
.
widget
<
TextField
>(
find
.
byType
(
TextField
));
expect
(
textField
.
controller
!.
selection
,
TextSelection
(
baseOffset:
delegate
.
query
.
length
,
extentOffset:
delegate
.
query
.
length
,
),
);
});
testWidgets
(
'Can open and close search'
,
(
WidgetTester
tester
)
async
{
final
_TestSearchDelegate
delegate
=
_TestSearchDelegate
();
final
List
<
String
>
selectedResults
=
<
String
>[];
...
...
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