Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ A few resources to get you started if this is your first Flutter project:
For help getting started with Flutter, view our
[online documentation](https://flutter.io/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
## ✅ Update
- Added a clearable search field in the home screen search card, making it easier to reset search text quickly.
Comment thread
Subhash-2005 marked this conversation as resolved.
Outdated
42 changes: 37 additions & 5 deletions lib/widgets/search_card.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
import 'package:flutter/material.dart';

class SearchCard extends StatelessWidget {
final TextEditingController _searchControl = new TextEditingController();
class SearchCard extends StatefulWidget {
@override
_SearchCardState createState() => _SearchCardState();
}

class _SearchCardState extends State<SearchCard> {
final TextEditingController _searchControl = TextEditingController();
bool _hasText = false;

void _onTextChanged() {
setState(() {
_hasText = _searchControl.text.isNotEmpty;
});
}
Comment thread
Subhash-2005 marked this conversation as resolved.

@override
void initState() {
super.initState();
_searchControl.addListener(_onTextChanged);
}

@override
void dispose() {
_searchControl.removeListener(_onTextChanged);
_searchControl.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -38,9 +63,16 @@ class SearchCard extends StatelessWidget {
Icons.search,
color: Colors.black,
),
suffixIcon: Icon(
Icons.filter_list,
color: Colors.black,
suffixIcon: IconButton(
icon: Icon(
_hasText ? Icons.clear : Icons.filter_list,
color: Colors.black,
),
onPressed: _hasText
? () {
_searchControl.clear();
}
: null,
),
Comment thread
Subhash-2005 marked this conversation as resolved.
Outdated
hintStyle: TextStyle(
fontSize: 15.0,
Expand Down