0

I am currently developing an application in flutter where the user types a text, which I send through an API POST request. I'm currently able to get the text and send it and get a response, it works fine.

The thing is, I want to allow the user to write multiple messages successively, before sending the request to the API; something like that:

  • user types message
  • user presses send message
  • wait to see if user is typing another message before sending the API request
  • if user is typing, wait till he presses send, and make one API request with both messages

I don't know if that is possible to do in flutter. I read about debounce() method of different packages but i saw that it works witha delay, does it also work with checking for typing conditions?

Any help is appreciated, thanks!

  • The crux of my question of your question... is how long should the code wait? For instance, if the user _is_ typing another message afterwards, how long should we wait before they add that message before we send the API request? That's where debounce comes in. – S.V. Apr 19 '21 at 20:08
  • I was going to say something very similar to @DrSatan1. You can set up a delay using a `Timer` & use a `TextEditingController` to monitor the textfield's usage. – Eli Front Apr 19 '21 at 20:20
  • @DrSatan1 & EliFront thanks for answering. So supposing I have a delay of 3 seconds, would I be using debounce() with a that delay, but how would I be checking the texteditingcontroller for him typing while that delay is happening? – mazendia Apr 19 '21 at 20:48
  • Basically like this: https://stackoverflow.com/a/52930197/2375907 Add any additional logic you may want inside of the `_onSearchChanged` (or equivalent) function. So to understand whether the user is typing, simply check whether the timer is still active! (Hope I understood correctly) – S.V. Apr 19 '21 at 20:52
  • Also, perhaps look at: https://stackoverflow.com/q/53146151/2375907 – S.V. Apr 19 '21 at 20:53

0 Answers0