Reputation: 23
I would like to know if it's possible, say someone types something in the search bar and the onChange instance sends every time a request to the server. Is it possible to say the program should wait for 2 seconds? After this time it should query the server. The only thing that I know is Future.delay but the thing is. It only delays the request I think so.
thank you for your help guys.
Upvotes: 0
Views: 868
Reputation: 53
onChanged: (_) async {
await Future.delayed(Duration(seconds: 2));
[Your function that triggers contact to the server]
};
It will pause for 2 seconds before making request to the server.
If you want user to press certain button that will make request to the server then user TextEditingController.
TextEditingController _controller = TextEditingController();
TextFormField(
controller: _controller;
)
Now you can use _controller.text to get the input and use this text to make request to the server as a parameter.
Upvotes: 1