flutter async function is being skipped

Viewed 178

So I was trying to organize my code and breaking it down into smaller functions when I discovered that a function is being skipped by Dart for some reason, if somebody is versed well with async programming; an explination for why this is happening would be appreciated.

The code:

  void _converse(bool first_run) async {
    first_run ? _speak("how may I help you?") : _speak("need anything else?");
    sleep(Duration(seconds: 3));
    await _listen();// the _listen function
    sleep(Duration(seconds: 10));

    first_run = false;
  }

_listen() code:

Future _listen() async {
    String _question = '-';
    if (!_isListening) {
      bool available = await _speech.initialize(
        onStatus: (val) => print('onStatus: $val'),
        onError: (val) => print('onError: $val'),
      );

      if (available) {
        setState(() => _isListening = true);
        _speech.listen(
          onResult: (val) => setState(() {
            _text = val.recognizedWords;
            if (val.hasConfidenceRating && val.confidence > 0) {
              _confidence = val.confidence;
            }
          }),
        );
      }
    } else {
      setState(() => _isListening = false);
      // test placeholder

      process_speech(_text);
      _speech.stop();
    }
  }

The _listen() function which is supposed to take in speech input is being ignored.

0 Answers
Related