Skip to content

Commit

Permalink
Merge pull request #27 from dagimg-dot/feat/clear-button
Browse files Browse the repository at this point in the history
feat: add clear button for the search box (resolves #26)
  • Loading branch information
dagmawibabi authored Sep 4, 2024
2 parents 78f0149 + c2031e0 commit 35f5509
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/components/search_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ class SearchBox extends StatefulWidget {
}

class _SearchBoxState extends State<SearchBox> {
@override
void initState() {
super.initState();
widget.searchTermController.addListener(() {
setState(() {});
});
}

@override
void dispose() {
widget.searchTermController.dispose();
super.dispose();
}

void clearSearchQuery() {
widget.searchTermController.clear();
}

@override
Widget build(BuildContext context) {
return Container(
Expand Down Expand Up @@ -64,6 +82,18 @@ class _SearchBoxState extends State<SearchBox> {
hintText: "Search...",
hintStyle: TextStyle(color: Colors.grey[700]),
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(vertical: 15.0),
suffixIcon: widget.searchTermController.text.isNotEmpty
? IconButton(
onPressed: () {
clearSearchQuery();
},
icon: const Icon(
Icons.clear,
color: Colors.grey,
),
)
: null,
),
onSubmitted: (searchTerm) {
widget.searchFunction(resetPagination: true);
Expand Down

0 comments on commit 35f5509

Please sign in to comment.