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
5805f454
Unverified
Commit
5805f454
authored
Aug 08, 2022
by
Greg Spencer
Committed by
GitHub
Aug 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix autocomplete selections (#109185)
parent
7dbe57d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
23 deletions
+98
-23
autocomplete.dart
packages/flutter/lib/src/widgets/autocomplete.dart
+28
-23
autocomplete_test.dart
packages/flutter/test/widgets/autocomplete_test.dart
+70
-0
No files found.
packages/flutter/lib/src/widgets/autocomplete.dart
View file @
5805f454
...
...
@@ -16,6 +16,7 @@ import 'framework.dart';
import
'inherited_notifier.dart'
;
import
'overlay.dart'
;
import
'shortcuts.dart'
;
import
'tap_region.dart'
;
/// The type of the [RawAutocomplete] callback which computes the list of
/// optional completions for the widget's field, based on the text the user has
...
...
@@ -421,13 +422,15 @@ class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>>
link:
_optionsLayerLink
,
showWhenUnlinked:
false
,
targetAnchor:
Alignment
.
bottomLeft
,
child:
AutocompleteHighlightedOption
(
highlightIndexNotifier:
_highlightedOptionIndex
,
child:
Builder
(
builder:
(
BuildContext
context
)
{
return
widget
.
optionsViewBuilder
(
context
,
_select
,
_options
);
}
)
child:
TextFieldTapRegion
(
child:
AutocompleteHighlightedOption
(
highlightIndexNotifier:
_highlightedOptionIndex
,
child:
Builder
(
builder:
(
BuildContext
context
)
{
return
widget
.
optionsViewBuilder
(
context
,
_select
,
_options
);
}
)
),
),
);
},
...
...
@@ -527,22 +530,24 @@ class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>>
@override
Widget
build
(
BuildContext
context
)
{
return
Container
(
key:
_fieldKey
,
child:
Shortcuts
(
shortcuts:
_shortcuts
,
child:
Actions
(
actions:
_actionMap
,
child:
CompositedTransformTarget
(
link:
_optionsLayerLink
,
child:
widget
.
fieldViewBuilder
==
null
?
const
SizedBox
.
shrink
()
:
widget
.
fieldViewBuilder
!(
context
,
_textEditingController
,
_focusNode
,
_onFieldSubmitted
,
),
return
TextFieldTapRegion
(
child:
Container
(
key:
_fieldKey
,
child:
Shortcuts
(
shortcuts:
_shortcuts
,
child:
Actions
(
actions:
_actionMap
,
child:
CompositedTransformTarget
(
link:
_optionsLayerLink
,
child:
widget
.
fieldViewBuilder
==
null
?
const
SizedBox
.
shrink
()
:
widget
.
fieldViewBuilder
!(
context
,
_textEditingController
,
_focusNode
,
_onFieldSubmitted
,
),
),
),
),
),
...
...
packages/flutter/test/widgets/autocomplete_test.dart
View file @
5805f454
...
...
@@ -129,6 +129,76 @@ void main() {
expect
(
lastOptions
.
elementAt
(
5
),
'northern white rhinoceros'
);
});
testWidgets
(
'tapping on an option selects it'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
fieldKey
=
GlobalKey
();
final
GlobalKey
optionsKey
=
GlobalKey
();
late
Iterable
<
String
>
lastOptions
;
late
FocusNode
focusNode
;
late
TextEditingController
textEditingController
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
RawAutocomplete
<
String
>(
optionsBuilder:
(
TextEditingValue
textEditingValue
)
{
return
kOptions
.
where
((
String
option
)
{
return
option
.
contains
(
textEditingValue
.
text
.
toLowerCase
());
});
},
fieldViewBuilder:
(
BuildContext
context
,
TextEditingController
fieldTextEditingController
,
FocusNode
fieldFocusNode
,
VoidCallback
onFieldSubmitted
)
{
focusNode
=
fieldFocusNode
;
textEditingController
=
fieldTextEditingController
;
return
TextField
(
key:
fieldKey
,
focusNode:
focusNode
,
controller:
textEditingController
,
);
},
optionsViewBuilder:
(
BuildContext
context
,
AutocompleteOnSelected
<
String
>
onSelected
,
Iterable
<
String
>
options
)
{
lastOptions
=
options
;
return
Material
(
elevation:
4.0
,
child:
ListView
.
builder
(
key:
optionsKey
,
padding:
const
EdgeInsets
.
all
(
8.0
),
itemCount:
options
.
length
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
final
String
option
=
options
.
elementAt
(
index
);
return
GestureDetector
(
onTap:
()
{
onSelected
(
option
);
},
child:
ListTile
(
title:
Text
(
option
),
),
);
},
),
);
},
),
),
),
);
// The field is always rendered, but the options are not unless needed.
expect
(
find
.
byKey
(
fieldKey
),
findsOneWidget
);
expect
(
find
.
byKey
(
optionsKey
),
findsNothing
);
// Tap on the text field to open the options.
await
tester
.
tap
(
find
.
byKey
(
fieldKey
));
await
tester
.
pump
();
expect
(
find
.
byKey
(
optionsKey
),
findsOneWidget
);
expect
(
lastOptions
.
length
,
kOptions
.
length
);
await
tester
.
tap
(
find
.
text
(
kOptions
[
2
]));
await
tester
.
pump
();
expect
(
find
.
byKey
(
optionsKey
),
findsNothing
);
expect
(
textEditingController
.
text
,
equals
(
kOptions
[
2
]));
});
testWidgets
(
'can filter and select a list of custom User options'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
fieldKey
=
GlobalKey
();
final
GlobalKey
optionsKey
=
GlobalKey
();
...
...
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