'Code execution stopped at await in async function in flutter while implementing Text to Speech

I am trying the text to speech feature in a flutter, but it is not working. I tried many code examples from the internet and googled but did not find why not working in my project.

To keep it simple I was trying in one simple file but still, it is not working.

On click of a button, the first print statement is executing but after that not get anything.

Below is the code

import 'package:flutter/material.dart';
import 'package:flutter_tts/flutter_tts.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  late FlutterTts flutterTts;

  @override
  initState() {
    super.initState();
    initTts();
  }

  initTts() {
    flutterTts = FlutterTts();
  }

  @override
  void dispose() {
    super.dispose();
    flutterTts.stop();
  }

  Future _speak() async {
    print("1");
    await flutterTts.speak("Hello");
    print("2");
  }

  @override
  Widget build(BuildContext context) {
     return MaterialApp(
  home: Scaffold(
    appBar: AppBar(
      title: Text('Flutter TTS'),
    ),
    body:  InkWell(
              onTap: _speak,
              child: Text("Click"),

            )
      ),
    );

} }

The console output is

Performing hot reload...

Syncing files to device Android SDK built for x86...

Reloaded 1 of 568 libraries in 544ms.

I/flutter (21300): 1



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source