Skip to content

Commit

Permalink
Redid everything with requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
urwrstkn8mare committed Mar 28, 2020
1 parent 32747ce commit 04ee6eb
Showing 1 changed file with 51 additions and 37 deletions.
88 changes: 51 additions & 37 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,38 +216,43 @@ class SearchBar<T> extends StatefulWidget {
/// Set a padding on the list
final EdgeInsetsGeometry listPadding;

SearchBar({
Key key,
@required this.onSearch,
@required this.onItemFound,
this.searchBarController,
this.minimumChars = 3,
this.debounceDuration = const Duration(milliseconds: 500),
this.loader = const Center(child: CircularProgressIndicator()),
this.onError,
this.emptyWidget = const SizedBox.shrink(),
this.header,
this.placeHolder,
this.icon = const Icon(Icons.search),
this.hintText = "",
this.hintStyle = const TextStyle(color: Color.fromRGBO(142, 142, 147, 1)),
this.iconActiveColor = Colors.black,
this.textStyle = const TextStyle(color: Colors.black),
this.cancellationWidget = const Text("Cancel"),
this.onCancelled,
this.suggestions = const [],
this.buildSuggestion,
this.searchBarStyle = const SearchBarStyle(),
this.crossAxisCount = 1,
this.shrinkWrap = false,
this.indexedScaledTileBuilder,
this.scrollDirection = Axis.vertical,
this.mainAxisSpacing = 0.0,
this.crossAxisSpacing = 0.0,
this.listPadding = const EdgeInsets.all(0),
this.searchBarPadding = const EdgeInsets.all(0),
this.headerPadding = const EdgeInsets.all(0),
}) : super(key: key);
/// The space in the width of the space bar to
/// allocate for the cancellation widget.
final double cancellationWidgetSpaceWidth;

SearchBar(
{Key key,
@required this.onSearch,
@required this.onItemFound,
this.searchBarController,
this.minimumChars = 3,
this.debounceDuration = const Duration(milliseconds: 500),
this.loader = const Center(child: CircularProgressIndicator()),
this.onError,
this.emptyWidget = const SizedBox.shrink(),
this.header,
this.placeHolder,
this.icon = const Icon(Icons.search),
this.hintText = "",
this.hintStyle = const TextStyle(color: Color.fromRGBO(142, 142, 147, 1)),
this.iconActiveColor = Colors.black,
this.textStyle = const TextStyle(color: Colors.black),
this.cancellationWidget = const Text("Cancel"),
this.onCancelled,
this.suggestions = const [],
this.buildSuggestion,
this.searchBarStyle = const SearchBarStyle(),
this.crossAxisCount = 1,
this.shrinkWrap = false,
this.indexedScaledTileBuilder,
this.scrollDirection = Axis.vertical,
this.mainAxisSpacing = 0.0,
this.crossAxisSpacing = 0.0,
this.listPadding = const EdgeInsets.all(0),
this.searchBarPadding = const EdgeInsets.all(0),
this.headerPadding = const EdgeInsets.all(0),
this.cancellationWidgetSpaceWidth})
: super(key: key);

@override
_SearchBarState createState() => _SearchBarState<T>();
Expand All @@ -268,7 +274,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 @@ -373,6 +380,12 @@ class _SearchBarState<T> extends State<SearchBar<T>>

@override
Widget build(BuildContext context) {
double _getCancellationWidth() {
return (widget.cancellationWidgetSpaceWidth != null
? widget.cancellationWidgetSpaceWidth
: MediaQuery.of(context).size.width * .2);
}

final widthMax = MediaQuery.of(context).size.width;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -387,7 +400,9 @@ class _SearchBarState<T> extends State<SearchBar<T>>
Flexible(
child: AnimatedContainer(
duration: Duration(milliseconds: 200),
width: _animate ? widthMax * .8 : widthMax,
width: _animate
? widthMax - _getCancellationWidth()
: widthMax,
decoration: BoxDecoration(
borderRadius: widget.searchBarStyle.borderRadius,
color: widget.searchBarStyle.backgroundColor,
Expand Down Expand Up @@ -421,8 +436,7 @@ class _SearchBarState<T> extends State<SearchBar<T>>
duration: Duration(milliseconds: _animate ? 1000 : 0),
child: AnimatedContainer(
duration: Duration(milliseconds: 200),
width:
_animate ? MediaQuery.of(context).size.width * .2 : 0,
width: _animate ? _getCancellationWidth() : 0,
child: Container(
color: Colors.transparent,
child: Center(
Expand Down

0 comments on commit 04ee6eb

Please sign in to comment.