fix: img loading on changing search text
This commit is contained in:
@@ -73,6 +73,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
List<GymCategory> categories = [];
|
List<GymCategory> categories = [];
|
||||||
GymCategory? selectedCategory;
|
GymCategory? selectedCategory;
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
final TextEditingController _searchField = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -123,6 +124,9 @@ class _MainPageState extends State<MainPage> {
|
|||||||
|
|
||||||
void _onSearch() {
|
void _onSearch() {
|
||||||
final categoryId = selectedCategory == null ? '' : selectedCategory!.id;
|
final categoryId = selectedCategory == null ? '' : selectedCategory!.id;
|
||||||
|
setState(() {
|
||||||
|
searchText = _searchField.text.trim().toLowerCase();
|
||||||
|
});
|
||||||
_searchItems(searchText: searchText, categoryId: categoryId);
|
_searchItems(searchText: searchText, categoryId: categoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,12 +145,13 @@ class _MainPageState extends State<MainPage> {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
onChanged: (value) => setState(() {
|
onChanged: (value) {
|
||||||
searchText = value.trim().toLowerCase();
|
searchText = value.trim().toLowerCase();
|
||||||
if (searchText == '') {
|
if (searchText == '') {
|
||||||
_onSearch();
|
_onSearch();
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
|
controller: _searchField,
|
||||||
textInputAction: TextInputAction.search,
|
textInputAction: TextInputAction.search,
|
||||||
onSubmitted: (_) => _onSearch(),
|
onSubmitted: (_) => _onSearch(),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
|
|||||||
Reference in New Issue
Block a user