Skip to content

Commit

Permalink
Merge pull request felixmccuaig#59 from dsolonenko/master
Browse files Browse the repository at this point in the history
Allow to set autofocus
  • Loading branch information
felixmccuaig authored Jun 11, 2022
2 parents c1b9aa9 + e90adb7 commit 6ed2235
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/autocomplete_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AutoCompleteTextField<T> extends StatefulWidget {
final TextCapitalization textCapitalization;
final TextEditingController controller;
final FocusNode focusNode;
final bool autofocus;

AutoCompleteTextField(
{@required
Expand Down Expand Up @@ -64,6 +65,7 @@ class AutoCompleteTextField<T> extends StatefulWidget {
this.minLength = 1,
this.controller,
this.focusNode,
this.autofocus = false,
this.unFocusOnItemSubmitted = true})
: super(key: key);

Expand Down Expand Up @@ -114,7 +116,9 @@ class AutoCompleteTextField<T> extends StatefulWidget {
textInputAction,
controller,
focusNode,
unFocusOnItemSubmitted);
autofocus,
unFocusOnItemSubmitted
);
}

class AutoCompleteTextFieldState<T> extends State<AutoCompleteTextField> {
Expand All @@ -135,6 +139,7 @@ class AutoCompleteTextFieldState<T> extends State<AutoCompleteTextField> {
bool submitOnSuggestionTap, clearOnSubmit, unFocusOnItemSubmitted;
TextEditingController controller;
FocusNode focusNode;
bool autofocus;

String currentText = "";

Expand Down Expand Up @@ -166,14 +171,17 @@ class AutoCompleteTextFieldState<T> extends State<AutoCompleteTextField> {
this.textInputAction,
this.controller,
this.focusNode,
this.unFocusOnItemSubmitted) {
this.autofocus,
this.unFocusOnItemSubmitted
) {
textField = new TextField(
inputFormatters: inputFormatters,
textCapitalization: textCapitalization,
decoration: decoration,
style: style,
keyboardType: keyboardType,
focusNode: focusNode ?? new FocusNode(),
autofocus: autofocus,
controller: controller ?? new TextEditingController(),
textInputAction: textInputAction,
onChanged: (newText) {
Expand Down Expand Up @@ -248,6 +256,7 @@ class AutoCompleteTextFieldState<T> extends State<AutoCompleteTextField> {
style: this.style,
keyboardType: this.keyboardType,
focusNode: focusNode ?? new FocusNode(),
autofocus: autofocus,
controller: controller ?? new TextEditingController(),
textInputAction: this.textInputAction,
onChanged: (newText) {
Expand Down Expand Up @@ -393,6 +402,7 @@ class SimpleAutoCompleteTextField extends AutoCompleteTextField<String> {
final ValueSetter<bool> onFocusChanged;
final TextEditingController controller;
final FocusNode focusNode;
final bool autofocus;

SimpleAutoCompleteTextField(
{TextStyle style,
Expand All @@ -403,6 +413,7 @@ class SimpleAutoCompleteTextField extends AutoCompleteTextField<String> {
this.minLength = 1,
this.controller,
this.focusNode,
this.autofocus = false,
TextInputType keyboardType: TextInputType.text,
@required GlobalKey<AutoCompleteTextFieldState<String>> key,
@required List<String> suggestions,
Expand Down Expand Up @@ -455,5 +466,7 @@ class SimpleAutoCompleteTextField extends AutoCompleteTextField<String> {
textInputAction,
controller,
focusNode,
unFocusOnItemSubmitted);
autofocus,
unFocusOnItemSubmitted
);
}

0 comments on commit 6ed2235

Please sign in to comment.