Skip to content

Commit 3373a0f

Browse files
committed
Created Docs
1 parent f7bd1ac commit 3373a0f

7 files changed

+304
-96
lines changed

Diff for: .idea/workspace.xml

+123-60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## [0.0.1] - TODO: Add release date.
1+
[1.0.0]
22

3-
* TODO: Describe initial release.
3+
Works great published version 1

Diff for: autocomplete_textfield.iml

+7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@
3434
<excludeFolder url="file://$MODULE_DIR$/example/android/gradle/wrapper/packages" />
3535
<excludeFolder url="file://$MODULE_DIR$/example/android/packages" />
3636
<excludeFolder url="file://$MODULE_DIR$/example/build" />
37+
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/packages" />
38+
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/Flutter.framework/Headers/packages" />
39+
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/Flutter.framework/Modules/packages" />
40+
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/Flutter.framework/packages" />
41+
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/flutter_assets/fonts/packages" />
42+
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/flutter_assets/packages" />
3743
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/packages" />
44+
<excludeFolder url="file://$MODULE_DIR$/example/ios/Frameworks/packages" />
3845
<excludeFolder url="file://$MODULE_DIR$/example/ios/Runner.xcodeproj/packages" />
3946
<excludeFolder url="file://$MODULE_DIR$/example/ios/Runner.xcodeproj/project.xcworkspace/packages" />
4047
<excludeFolder url="file://$MODULE_DIR$/example/ios/Runner.xcodeproj/xcshareddata/packages" />

Diff for: doc/autocomplete_textfield.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# AutoCompleteTextField Docs
2+
3+
## Usage
4+
5+
AutoCompleteTextField is typed to allow any data type to be used. However most common use case is with string types.
6+
7+
8+
# Fields
9+
10+
## @required
11+
12+
### key
13+
14+
A global key of type GlobalKey<AutoCompleteTextFieldState<T>> where T is the data type of the suggestions is required
15+
so the text field may be cleared dynamically.
16+
17+
### suggestions
18+
19+
A List<T> is provided. Each item in suggestions represents a possible suggestion such as a list of foods.
20+
21+
### itemBuilder
22+
23+
This is called for each suggestion:
24+
25+
`
26+
(context, suggestion) {
27+
28+
}
29+
30+
`
31+
32+
A widget must be returned, the most common use case for itemBuilder is
33+
`
34+
(context, suggestion) {
35+
return new Padding(
36+
padding: desired padding,
37+
child: new Text(suggestion)
38+
);
39+
}
40+
41+
`
42+
43+
### itemSorter
44+
45+
Sorts items:
46+
47+
`
48+
(a, b) {
49+
50+
}
51+
52+
`
53+
54+
For string implementation (sorting A-Z)
55+
56+
`
57+
(a, b) {
58+
return a.compareTo(b);
59+
}
60+
61+
`
62+
Can be used.
63+
64+
### itemFilter
65+
66+
Filters items based on the search query (return true or false)
67+
68+
`
69+
(item, query) {
70+
71+
}
72+
`
73+
74+
A common use case with strings is
75+
76+
`
77+
(item, query) {
78+
item.toLowerCase().startsWith(query.toLowerCase());
79+
}
80+
`
81+
82+
Note that .toLowerCase() is used as if the user searched 'Ap'
83+
84+
And the possible suggestions were
85+
86+
'Apple',
87+
'appletree'
88+
89+
without the use of .ToLowerCase() only Apple would be a suggestion.
90+
91+
92+
## non-required fields
93+
94+
### suggestionsAmount
95+
96+
By default only 5 suggestions will be returned, this can be customised with this field
97+
98+
### style, decoration, textInputAction and keyboardType
99+
100+
Are TextField parameters refer to [here](https://docs.flutter.io/flutter/material/TextField-class.html)

Diff for: example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ packages:
2828
path: ".."
2929
relative: true
3030
source: path
31-
version: "0.0.1"
31+
version: "1.0.0"
3232
boolean_selector:
3333
dependency: transitive
3434
description:

Diff for: lib/autocomplete_textfield.dart

+69-31
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,90 @@ class AutoCompleteTextField<T> extends StatefulWidget {
1313
List<T> suggestions;
1414
Filter<T> itemFilter;
1515
Comparator<T> itemSorter;
16-
StringCallback textChanged;
16+
StringCallback textChanged, textSubmitted;
1717
AutoCompleteOverlayItemBuilder<T> itemBuilder;
1818
int suggestionsAmount;
1919
GlobalKey<AutoCompleteTextFieldState<T>> key;
2020

21+
InputDecoration decoration;
22+
TextStyle style;
23+
TextInputAction textInputAction;
24+
TextInputType keyboardType;
25+
2126
AutoCompleteTextField(
22-
{@required this.key,
23-
@required this.suggestions,
24-
@required this.textChanged,
25-
@required this.itemBuilder,
26-
@required this.itemSorter,
27-
@required this.itemFilter,
28-
this.suggestionsAmount : 5}) : super(key: key);
27+
{this.style,
28+
this.decoration: const InputDecoration(),
29+
this.textChanged,
30+
this.textSubmitted,
31+
this.textInputAction: TextInputAction.done,
32+
this.keyboardType: TextInputType.text,
33+
@required this.key,
34+
@required this.suggestions,
35+
@required this.itemBuilder,
36+
@required this.itemSorter,
37+
@required this.itemFilter,
38+
this.suggestionsAmount: 5})
39+
: super(key: key);
2940

3041
void clear() {
3142
key.currentState.textField.controller.clear();
3243
}
3344

3445
@override
3546
State<StatefulWidget> createState() => new AutoCompleteTextFieldState<T>(
36-
suggestions, textChanged, itemBuilder, itemSorter, itemFilter, suggestionsAmount);
47+
suggestions,
48+
textChanged,
49+
textSubmitted,
50+
itemBuilder,
51+
itemSorter,
52+
itemFilter,
53+
suggestionsAmount,
54+
decoration,
55+
style,
56+
textInputAction,
57+
keyboardType);
3758
}
3859

3960
class AutoCompleteTextFieldState<T> extends State<AutoCompleteTextField> {
4061
TextField textField;
4162
List<T> suggestions;
42-
StringCallback textChanged;
63+
StringCallback textChanged, textSubmitted;
4364
AutoCompleteOverlayItemBuilder<T> itemBuilder;
4465
Comparator<T> itemSorter;
4566
OverlayEntry listSuggestionsEntry;
4667
List<T> filteredSuggestions;
4768
Filter<T> itemFilter;
4869
int suggestionsAmount;
4970

50-
AutoCompleteTextFieldState(this.suggestions, this.textChanged,
51-
this.itemBuilder, this.itemSorter, this.itemFilter, this.suggestionsAmount) {
71+
AutoCompleteTextFieldState(
72+
this.suggestions,
73+
this.textChanged,
74+
this.textSubmitted,
75+
this.itemBuilder,
76+
this.itemSorter,
77+
this.itemFilter,
78+
this.suggestionsAmount,
79+
InputDecoration decoration,
80+
TextStyle style,
81+
TextInputAction textInputAction,
82+
TextInputType keyboardType) {
5283
textField = new TextField(
84+
decoration: decoration,
85+
style: style,
86+
textInputAction: textInputAction,
87+
keyboardType: keyboardType,
5388
focusNode: new FocusNode(),
5489
controller: new TextEditingController(),
5590
onChanged: (newText) {
5691
textChanged(newText);
5792
updateOverlay(newText);
5893
},
94+
onSubmitted: (submittedText) {
95+
textSubmitted(submittedText);
96+
},
5997
);
6098
textField.focusNode.addListener(() {
61-
if(!textField.focusNode.hasFocus) {
99+
if (!textField.focusNode.hasFocus) {
62100
filteredSuggestions = [];
63101
}
64102
});
@@ -89,28 +127,28 @@ class AutoCompleteTextFieldState<T> extends State<AutoCompleteTextField> {
89127
width: width,
90128
child: new Card(
91129
child: new Column(
92-
children: filteredSuggestions.map((suggestion) {
93-
return new Row(children: [
94-
new Expanded(
95-
child: new InkWell(
96-
child: itemBuilder(context, suggestion),
97-
onTap: () {
98-
setState(() {
99-
String newText = suggestion.toString();
100-
textField.controller.text = newText;
101-
textField.focusNode.unfocus();
102-
textChanged(newText);
103-
});
104-
}))
105-
]);
106-
}).toList(),
107-
))));
130+
children: filteredSuggestions.map((suggestion) {
131+
return new Row(children: [
132+
new Expanded(
133+
child: new InkWell(
134+
child: itemBuilder(context, suggestion),
135+
onTap: () {
136+
setState(() {
137+
String newText = suggestion.toString();
138+
textField.controller.text = newText;
139+
textField.focusNode.unfocus();
140+
textChanged(newText);
141+
});
142+
}))
143+
]);
144+
}).toList(),
145+
))));
108146
});
109147
Overlay.of(context).insert(listSuggestionsEntry);
110148
}
111149

112-
filteredSuggestions =
113-
getSuggestions(suggestions, itemSorter, itemFilter, suggestionsAmount, query);
150+
filteredSuggestions = getSuggestions(
151+
suggestions, itemSorter, itemFilter, suggestionsAmount, query);
114152
listSuggestionsEntry.markNeedsBuild();
115153
}
116154

Diff for: pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: autocomplete_textfield
2-
description: An autocomplete textfield for flutter
3-
version: 0.0.2
2+
description: A simple and versatile autocomplete text field for flutter
3+
version: 1.0.0
44
author: Felix McCuaig <[email protected]>
55
homepage: https://github.com/felixlucien/flutter-autocomplete-textfield
66

0 commit comments

Comments
 (0)