Unable to stop Vapi while in connecting state (Flu...
# support
k
In Flutter, stopping a Vapi call works correctly after the call has started. However, if the stop button is pressed before the call is established (while Vapi is still connecting), the connection does not stop. Behavior stop() works once the call is active. If stop() is triggered during the connecting phase, Vapi continues connecting. vapi.on("call-started") still fires later, and the call starts anyway. Console logs confirm “Call has started” even though stop was already invoked. This looks like a race condition in the pre-call lifecycle. Same issue reproducible consistently in Flutter. Question Is there a supported way to cancel / abort a pending connection before call-started fires? Is there an internal state or event we should wait for or handle differently in Flutter?
v
Try attaching your stop logic to the earliest call lifecycle event available. For example, in the web SDK, you can listen for the 'call-start' and 'call-end' events and manage state accordingly:
Copy code
js
vapi.on('call-start', () => {
  // Call has started
});
vapi.on('call-end', () => {
  // Call has ended
});
If your Flutter SDK exposes similar events, ensure you check and handle the connecting state before 'call-started' fires, and invoke
stop()
as soon as possible in your event flow. Refer to the [Vapi Voice Widget event handling example](https://docs.vapi.ai/assistants/examples/voice-widget) for more details. Source: - [Vapi Voice Widget Example](https://docs.vapi.ai/assistants/examples/voice-widget)
d
+1
c
This has been reported to the technical team for further debugging. In the meantime, if you need an immediate solution, you can consider one of the following approaches: - Disable the Stop button until the call is fully connected (this can be traced using event listeners). - When the stop button is pressed, implement a timeout that retries every 500 ms to check whether the call is active, and then trigger the stop action based. Let me know if you need help implementing either approach.
d
still it's not resolved
c
Yeah, not fixed yet, have you tried the alternative I suggested? It should fix your problem in the meantime.