title: I'm trying to build a text to speech, am using flutter_tts package but I'm running into a fatal error when i try to debug on my android mobile
body: <p>I'm trying to build a text to speech app but I'm getting this fatal error when i try debug using my android mobile.
  I noticed that when I run my app as web app,it is working just okay..the error seems to be caused by <strong>flutter_tts_web</strong> package which I'm required to import for controlling the <strong>TtsState</strong>, any help will be highly appreciated</p>
  <hr />
  <p>Error I'm getting:</p>
  <p>Invalid depfile: C:\Users\ENKATE\Documents\example.dart_tool\flutter_build\211b4f6761bfd841fe4d9a18786a4cd6\kernel_snapshot.d
  /C:/SDKs/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_tts-3.5.0/lib/flutter_tts_web.dart:3:8: Error: Not found: 'dart:js'
  import 'dart:js' as js;
  ^
  /C:/SDKs/flutter/packages/flutter_web_plugins/lib/src/navigation/js_url_strategy.dart:13:8: Error: Not found: 'dart:html'
  import 'dart:html' as html;
  ^
  /C:/SDKs/flutter/packages/flutter_web_plugins/lib/src/navigation/url_strategy.dart:6:8: Error: Not found: 'dart:html'
  import 'dart:html' as html;
  ^
  /C:/SDKs/flutter/packages/flutter_web_plugins/lib/src/navigation/utils.dart:5:8: Error: Not found: 'dart:html'
  import 'dart:html';
  ^
  /C:/SDKs/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.4/lib/js.dart:8:1: Error: Not found: 'dart:js'
  export 'dart:js' show allowInterop, allowInteropCaptureThis;
  ^
  /C:/SDKs/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_tts-3.5.0/lib/flutter_tts_web.dart:34:8: Error: Type 'js.JsObject' not found.
  late js.JsObject synth;
  ^^^^^^^^^^^
  /C:/SDKs/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_tts-3.5.0/lib/flutter_tts_web.dart:35:8: Error: Type 'js.JsObject' not found.
  late js.JsObject utterance;</p>
  <pre><code>   ^^^^^^^^^^^
  </code></pre>
  <p>/C:/SDKs/flutter/packages/flutter_web_plugins/lib/src/navigation/js_url_strategy.dart:79:48: Error: Type 'html.EventListener' not found.</p>
  <p>Sample code below:</p>
  <pre><code>import 'dart:async';
  import 'dart:io' show Platform;
  import 'package:flutter/foundation.dart' show kIsWeb;
  import 'package:flutter/material.dart';
  import 'package:flutter_tts/flutter_tts.dart';
  import 'package:flutter_tts/flutter_tts_web.dart';
  
  void main() {
    runApp(const MyApp());
  }
  
  class MyApp extends StatelessWidget {
    const MyApp({Key? key}) : super(key: key);
  
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(title: 'Flutter Demo Home Page'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    const MyHomePage({Key? key, required this.title}) : super(key: key);
    final String title;
  
    @override
    State&lt;MyHomePage&gt; createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    late FlutterTts flutterTts;
    String? language;
    String? engine;
    double volume = 0.5;
    double pitch = 1.0;
    double rate = 0.5;
    bool isCurrentLanguageInstalled = false;
  
    String? _newVoiceText;
    int? _inputLength;
  
    TtsState ttsState = TtsState.stopped;
  
    get isPlaying =&gt; ttsState == TtsState.playing;
    get isStopped =&gt; ttsState == TtsState.stopped;
    get isPaused =&gt; ttsState == TtsState.paused;
    get isContinued =&gt; ttsState == TtsState.continued;
  
    bool get isIOS =&gt; !kIsWeb &amp;&amp; Platform.isIOS;
    bool get isAndroid =&gt; !kIsWeb &amp;&amp; Platform.isAndroid;
    bool get isWindows =&gt; !kIsWeb &amp;&amp; Platform.isWindows;
    bool get isWeb =&gt; kIsWeb;
  
    @override
    initState() {
      super.initState();
      initTts();
    }
  
    initTts() {
      flutterTts = FlutterTts();
  
      _setAwaitOptions();
  
      if (isAndroid) {
        _getDefaultEngine();
      }
  
      flutterTts.setStartHandler(() {
        setState(() {
          print(&quot;Playing&quot;);
          ttsState = TtsState.playing;
        });
      });
  
      flutterTts.setCompletionHandler(() {
        setState(() {
          print(&quot;Complete&quot;);
          ttsState = TtsState.stopped;
        });
      });
  
      flutterTts.setCancelHandler(() {
        setState(() {
          print(&quot;Cancel&quot;);
          ttsState = TtsState.stopped;
        });
      });
  
      if (isWeb || isIOS || isWindows) {
        flutterTts.setPauseHandler(() {
          setState(() {
            print(&quot;Paused&quot;);
            ttsState = TtsState.paused;
          });
        });
  
        flutterTts.setContinueHandler(() {
          setState(() {
            print(&quot;Continued&quot;);
            ttsState = TtsState.continued;
          });
        });
      }
  
      flutterTts.setErrorHandler((msg) {
        setState(() {
          print(&quot;error: $msg&quot;);
          ttsState = TtsState.stopped;
        });
      });
    }
  
    Future&lt;dynamic&gt; _getLanguages() =&gt; flutterTts.getLanguages;
  
    Future&lt;dynamic&gt; _getEngines() =&gt; flutterTts.getEngines;
  
    Future _getDefaultEngine() async {
      var engine = await flutterTts.getDefaultEngine;
      if (engine != null) {
        print(engine);
      }
    }
  
    Future _speak() async {
      await flutterTts.setVolume(volume);
      await flutterTts.setSpeechRate(rate);
      await flutterTts.setPitch(pitch);
  
      if (_newVoiceText != null) {
        if (_newVoiceText!.isNotEmpty) {
          await flutterTts.speak(_newVoiceText!);
        }
      }
    }
  
    Future _setAwaitOptions() async {
      await flutterTts.awaitSpeakCompletion(true);
    }
  
    Future _stop() async {
      var result = await flutterTts.stop();
      if (result == 1) setState(() =&gt; ttsState = TtsState.stopped);
    }
  
    Future _pause() async {
      var result = await flutterTts.pause();
      if (result == 1) setState(() =&gt; ttsState = TtsState.paused);
    }
  
    @override
    void dispose() {
      super.dispose();
      flutterTts.stop();
    }
  
    List&lt;DropdownMenuItem&lt;String&gt;&gt; getEnginesDropDownMenuItems(dynamic engines) {
      var items = &lt;DropdownMenuItem&lt;String&gt;&gt;[];
      for (dynamic type in engines) {
        items.add(DropdownMenuItem(
            value: type as String?, child: Text(type as String)));
      }
      return items;
    }
  
    void changedEnginesDropDownItem(String? selectedEngine) {
      flutterTts.setEngine(selectedEngine!);
      language = null;
      setState(() {
        engine = selectedEngine;
      });
    }
  
    List&lt;DropdownMenuItem&lt;String&gt;&gt; getLanguageDropDownMenuItems(
        dynamic languages) {
      var items = &lt;DropdownMenuItem&lt;String&gt;&gt;[];
      for (dynamic type in languages) {
        items.add(DropdownMenuItem(
            value: type as String?, child: Text(type as String)));
      }
      return items;
    }
  
    void changedLanguageDropDownItem(String? selectedType) {
      setState(() {
        language = selectedType;
        flutterTts.setLanguage(language!);
        if (isAndroid) {
          flutterTts
              .isLanguageInstalled(language!)
              .then((value) =&gt; isCurrentLanguageInstalled = (value as bool));
        }
      });
    }
  
    void _onChange(String text) {
      setState(() {
        _newVoiceText = text;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text('Flutter TTS'),
          ),
          body: SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Column(
              children: [
                _inputSection(),
                _btnSection(),
                _engineSection(),
                _futureBuilder(),
                _buildSliders(),
                if (isAndroid) _getMaxSpeechInputLengthSection(),
              ],
            ),
          ),
        ),
      );
    }
  
    Widget _engineSection() {
      if (isAndroid) {
        return FutureBuilder&lt;dynamic&gt;(
            future: _getEngines(),
            builder: (BuildContext context, AsyncSnapshot&lt;dynamic&gt; snapshot) {
              if (snapshot.hasData) {
                return _enginesDropDownSection(snapshot.data);
              } else if (snapshot.hasError) {
                return Text('Error loading engines...');
              } else
                return Text('Loading engines...');
            });
      } else
        return Container(width: 0, height: 0);
    }
  
    Widget _futureBuilder() =&gt; FutureBuilder&lt;dynamic&gt;(
        future: _getLanguages(),
        builder: (BuildContext context, AsyncSnapshot&lt;dynamic&gt; snapshot) {
          if (snapshot.hasData) {
            return _languageDropDownSection(snapshot.data);
          } else if (snapshot.hasError) {
            return Text('Error loading languages...');
          } else
            return Text('Loading Languages...');
        });
  
    Widget _inputSection() =&gt; Container(
        alignment: Alignment.topCenter,
        padding: EdgeInsets.only(top: 25.0, left: 25.0, right: 25.0),
        child: TextField(
          onChanged: (String value) {
            _onChange(value);
          },
        ));
  
    Widget _btnSection() {
      if (isAndroid) {
        return Container(
            padding: EdgeInsets.only(top: 50.0),
            child:
                Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
              _buildButtonColumn(Colors.green, Colors.greenAccent,
                  Icons.play_arrow, 'PLAY', _speak),
              _buildButtonColumn(
                  Colors.red, Colors.redAccent, Icons.stop, 'STOP', _stop),
            ]));
      } else {
        return Container(
            padding: EdgeInsets.only(top: 50.0),
            child:
                Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
              _buildButtonColumn(Colors.green, Colors.greenAccent,
                  Icons.play_arrow, 'PLAY', _speak),
              _buildButtonColumn(
                  Colors.red, Colors.redAccent, Icons.stop, 'STOP', _stop),
              _buildButtonColumn(
                  Colors.blue, Colors.blueAccent, Icons.pause, 'PAUSE', _pause),
            ]));
      }
    }
  
    Widget _enginesDropDownSection(dynamic engines) =&gt; Container(
          padding: EdgeInsets.only(top: 50.0),
          child: DropdownButton(
            value: engine,
            items: getEnginesDropDownMenuItems(engines),
            onChanged: changedEnginesDropDownItem,
          ),
        );
  
    Widget _languageDropDownSection(dynamic languages) =&gt; Container(
        padding: EdgeInsets.only(top: 10.0),
        child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
          DropdownButton(
            value: language,
            items: getLanguageDropDownMenuItems(languages),
            onChanged: changedLanguageDropDownItem,
          ),
          Visibility(
            visible: isAndroid,
            child: Text(&quot;Is installed: $isCurrentLanguageInstalled&quot;),
          ),
        ]));
  
    Column _buildButtonColumn(Color color, Color splashColor, IconData icon,
        String label, Function func) {
      return Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            IconButton(
                icon: Icon(icon),
                color: color,
                splashColor: splashColor,
                onPressed: () =&gt; func()),
            Container(
                margin: const EdgeInsets.only(top: 8.0),
                child: Text(label,
                    style: TextStyle(
                        fontSize: 12.0,
                        fontWeight: FontWeight.w400,
                        color: color)))
          ]);
    }
  
    Widget _getMaxSpeechInputLengthSection() {
      return Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          ElevatedButton(
            child: Text('Get max speech input length'),
            onPressed: () async {
              _inputLength = await flutterTts.getMaxSpeechInputLength;
              setState(() {});
            },
          ),
          Text(&quot;$_inputLength characters&quot;),
        ],
      );
    }
  
    Widget _buildSliders() {
      return Column(
        children: [_volume(), _pitch(), _rate()],
      );
    }
  
    Widget _volume() {
      return Slider(
          value: volume,
          onChanged: (newVolume) {
            setState(() =&gt; volume = newVolume);
          },
          min: 0.0,
          max: 1.0,
          divisions: 10,
          label: &quot;Volume: $volume&quot;);
    }
  
    Widget _pitch() {
      return Slider(
        value: pitch,
        onChanged: (newPitch) {
          setState(() =&gt; pitch = newPitch);
        },
        min: 0.5,
        max: 2.0,
        divisions: 15,
        label: &quot;Pitch: $pitch&quot;,
        activeColor: Colors.red,
      );
    }
  
    Widget _rate() {
      return Slider(
        value: rate,
        onChanged: (newRate) {
          setState(() =&gt; rate = newRate);
        },
        min: 0.0,
        max: 1.0,
        divisions: 10,
        label: &quot;Rate: $rate&quot;,
        activeColor: Colors.green,
      );
    }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/WSgbt.png" rel="nofollow noreferrer">Error when trying to debug flutter android app</a></p>