Skip to content

Add clearable search button to home search bar#35

Open
Subhash-2005 wants to merge 2 commits into
JideGuru:masterfrom
Subhash-2005:feature/clearable-search
Open

Add clearable search button to home search bar#35
Subhash-2005 wants to merge 2 commits into
JideGuru:masterfrom
Subhash-2005:feature/clearable-search

Conversation

@Subhash-2005
Copy link
Copy Markdown

Updated [search_card.dart]
Converted SearchCard to a StatefulWidget
Added an interactive clear button that appears when search text is entered
Clears text when the button is tapped
Updated [README.md]
with a note describing the new feature

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request converts the SearchCard widget into a StatefulWidget to introduce a clearable search field functionality. Key changes include adding a TextEditingController listener to track input and dynamically switching the suffix icon between a clear button and a filter icon. Review feedback suggests standardizing the README header, optimizing the text change listener to prevent unnecessary state updates, and adjusting the suffix icon implementation to maintain consistent UI styling when the field is empty.

Comment thread README.md Outdated
Comment on lines +45 to +46
## ✅ Update
- Added a clearable search field in the home screen search card, making it easier to reset search text quickly.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The "Update" section header is non-standard for a project README. It is generally better to list new functionality under a "Features" section or simply update the project description to reflect the current state of the application.

Suggested change
## ✅ Update
- Added a clearable search field in the home screen search card, making it easier to reset search text quickly.
## 🚀 Features
- Added a clearable search field in the home screen search card, making it easier to reset search text quickly.

Comment on lines +12 to +16
void _onTextChanged() {
setState(() {
_hasText = _searchControl.text.isNotEmpty;
});
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling setState on every keystroke is slightly inefficient when the _hasText state hasn't actually changed (for example, when typing the second or third character). You can optimize this by checking if the state needs to be updated before calling setState.

Suggested change
void _onTextChanged() {
setState(() {
_hasText = _searchControl.text.isNotEmpty;
});
}
void _onTextChanged() {
if (_hasText != _searchControl.text.isNotEmpty) {
setState(() {
_hasText = _searchControl.text.isNotEmpty;
});
}
}

Comment thread lib/widgets/search_card.dart Outdated
Comment on lines 66 to 76
suffixIcon: IconButton(
icon: Icon(
_hasText ? Icons.clear : Icons.filter_list,
color: Colors.black,
),
onPressed: _hasText
? () {
_searchControl.clear();
}
: null,
),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using an IconButton with onPressed: null when there is no text causes the filter_list icon to appear disabled (usually greyed out) and adds extra padding compared to a standard Icon. Consider conditionally returning a plain Icon when the field is empty to maintain the original UI appearance and avoid the disabled styling.

Suggested change
suffixIcon: IconButton(
icon: Icon(
_hasText ? Icons.clear : Icons.filter_list,
color: Colors.black,
),
onPressed: _hasText
? () {
_searchControl.clear();
}
: null,
),
suffixIcon: _hasText
? IconButton(
icon: Icon(
Icons.clear,
color: Colors.black,
),
onPressed: () {
_searchControl.clear();
},
)
: Icon(
Icons.filter_list,
color: Colors.black,
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant