I want to implement a search textfield in my app which gets the result from API. but the problem is I call the API on the textfield's onChanged and when for example you type 'ab' first it call API for results of 'a' and as it takes some time to get result it would never call for 'ab' unless user type it very slowly. I want a Google-like autocompelete search.
TextField(
controller: searchController.textcontroller.value,
onChanged: (v) {
if (searchController.textcontroller.value.text != null ||
searchController.textcontroller.value.text.length > 0) {
searchController.getResult();
}
},
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20.0),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Search...',
hintStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20.0)),
),