added functionality to clear search text
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m38s
All checks were successful
Flutter APK Build / Build Flutter APK (push) Successful in 6m38s
This commit is contained in:
@@ -1,16 +1,34 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SearchBarWidget extends StatelessWidget {
|
||||
const SearchBarWidget({super.key, required this.onEditingComplete});
|
||||
const SearchBarWidget({
|
||||
super.key,
|
||||
required this.onEditingComplete,
|
||||
required this.onResetSearch,
|
||||
});
|
||||
|
||||
final Function(String searchString) onEditingComplete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(onChanged: (text) => onChanged(text, context));
|
||||
}
|
||||
final Function() onResetSearch;
|
||||
|
||||
void onChanged(String text, BuildContext context) {
|
||||
if (context.mounted) onEditingComplete(text);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final searchTextController = TextEditingController();
|
||||
return TextField(
|
||||
controller: searchTextController,
|
||||
onChanged: (text) => onChanged(text, context),
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
searchTextController.clear();
|
||||
onResetSearch();
|
||||
},
|
||||
icon: Icon(Icons.delete_outline_outlined),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user