Open mdsalman729 opened 3 years ago
Hi, I am getting this issue when i try to initialize the plugin through an async task.
E/flutter (11121): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method getLanguages on channel flutter_tts) E/flutter (11121): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7) E/flutter (11121): E/flutter (11121): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12) E/flutter (11121): #2 FlutterTts.getLanguages (package:flutter_tts/flutter_tts.dart:207:38) E/flutter (11121): #3 _MyAppState._getLanguages (package:example/main.dart:108:34) E/flutter (11121): #4 _MyAppState.initTts (package:example/main.dart:56:5) E/flutter (11121): #5 _MyAppState.initState (package:example/main.dart:50:5)
I currently have a handler listening for action process text event on android which allows me to share the text selected in other android apps with my flutter app. Here is my code -
class _MyAppState extends State { FlutterTts flutterTts; dynamic languages; String language; double volume = 0.5; double pitch = 1.0; double rate = 0.5; bool isCurrentLanguageInstalled = false;
String _newVoiceText;
TtsState ttsState = TtsState.stopped;
get isPlaying => ttsState == TtsState.playing; get isStopped => ttsState == TtsState.stopped; get isPaused => ttsState == TtsState.paused; get isContinued => ttsState == TtsState.continued;
bool get isIOS => !kIsWeb && Platform.isIOS; bool get isAndroid => !kIsWeb && Platform.isAndroid; bool get isWeb => kIsWeb;
String inputText = ''; Future initActionProcessText() async { inputText = await ActionProcessText.getInputText; //setState(() {}); //initTts(); }
@override initState() { super.initState(); initTts(); }
initTts() { flutterTts = FlutterTts();
_getLanguages(); if (isAndroid) { _getEngines(); } flutterTts.setStartHandler(() { setState(() { print("Playing"); ttsState = TtsState.playing; }); }); flutterTts.setCompletionHandler(() { setState(() { print("Complete"); ttsState = TtsState.stopped; }); }); flutterTts.setCancelHandler(() { setState(() { print("Cancel"); ttsState = TtsState.stopped; }); }); if (isWeb || isIOS) { flutterTts.setPauseHandler(() { setState(() { print("Paused"); ttsState = TtsState.paused; }); }); flutterTts.setContinueHandler(() { setState(() { print("Continued"); ttsState = TtsState.continued; }); }); } flutterTts.setErrorHandler((msg) { setState(() { print("error: $msg"); ttsState = TtsState.stopped; }); });
}
Future _getLanguages() async { languages = await flutterTts.getLanguages; if (languages != null) setState(() => languages); }
Future _getEngines() async { var engines = await flutterTts.getEngines; if (engines != null) { for (dynamic engine in engines) { print(engine); } } }
Any help would be appreciated.
Try to set languages in a FutureBuilder. I updated the example with something similar.
Hi, I am getting this issue when i try to initialize the plugin through an async task.
E/flutter (11121): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method getLanguages on channel flutter_tts) E/flutter (11121): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7) E/flutter (11121):
E/flutter (11121): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter (11121): #2 FlutterTts.getLanguages (package:flutter_tts/flutter_tts.dart:207:38)
E/flutter (11121): #3 _MyAppState._getLanguages (package:example/main.dart:108:34)
E/flutter (11121): #4 _MyAppState.initTts (package:example/main.dart:56:5)
E/flutter (11121): #5 _MyAppState.initState (package:example/main.dart:50:5)
I currently have a handler listening for action process text event on android which allows me to share the text selected in other android apps with my flutter app. Here is my code -
class _MyAppState extends State {
FlutterTts flutterTts;
dynamic languages;
String language;
double volume = 0.5;
double pitch = 1.0;
double rate = 0.5;
bool isCurrentLanguageInstalled = false;
String _newVoiceText;
TtsState ttsState = TtsState.stopped;
get isPlaying => ttsState == TtsState.playing; get isStopped => ttsState == TtsState.stopped; get isPaused => ttsState == TtsState.paused; get isContinued => ttsState == TtsState.continued;
bool get isIOS => !kIsWeb && Platform.isIOS; bool get isAndroid => !kIsWeb && Platform.isAndroid; bool get isWeb => kIsWeb;
String inputText = ''; Future initActionProcessText() async {
inputText = await ActionProcessText.getInputText;
//setState(() {});
//initTts();
}
@override initState() { super.initState(); initTts(); }
initTts() { flutterTts = FlutterTts();
}
Future _getLanguages() async { languages = await flutterTts.getLanguages; if (languages != null) setState(() => languages); }
Future _getEngines() async { var engines = await flutterTts.getEngines; if (engines != null) { for (dynamic engine in engines) { print(engine); } } }
Any help would be appreciated.