Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added autoFocus parameter #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/flappy_search_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class SearchBarController<T> {
CancelableOperation _cancelableOperation;
int minimumChars;

void setTextController(TextEditingController _searchQueryController, minimunChars) {
void setTextController(
TextEditingController _searchQueryController, minimunChars) {
this._searchQueryController = _searchQueryController;
this.minimumChars = minimunChars;
}
Expand Down Expand Up @@ -215,6 +216,9 @@ class SearchBar<T> extends StatefulWidget {
/// Set a padding on the list
final EdgeInsetsGeometry listPadding;

/// Define if search bar should be focused as soon as it is visible
final bool autoFocus;

SearchBar({
Key key,
@required this.onSearch,
Expand Down Expand Up @@ -246,6 +250,7 @@ class SearchBar<T> extends StatefulWidget {
this.listPadding = const EdgeInsets.all(0),
this.searchBarPadding = const EdgeInsets.all(0),
this.headerPadding = const EdgeInsets.all(0),
this.autoFocus = false,
}) : super(key: key);

@override
Expand All @@ -268,7 +273,8 @@ class _SearchBarState<T> extends State<SearchBar<T>>
searchBarController =
widget.searchBarController ?? SearchBarController<T>();
searchBarController.setListener(this);
searchBarController.setTextController(_searchQueryController, widget.minimumChars);
searchBarController.setTextController(
_searchQueryController, widget.minimumChars);
}

@override
Expand Down Expand Up @@ -398,6 +404,7 @@ class _SearchBarState<T> extends State<SearchBar<T>>
child: TextField(
controller: _searchQueryController,
onChanged: _onTextChanged,
autofocus: widget.autoFocus,
style: widget.textStyle,
decoration: InputDecoration(
icon: widget.icon,
Expand Down