0

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.

Michael
  • 13
  • 3

1 Answers1

1
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.

Kiran
  • 53
  • 1
  • 5