Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in library #439

Closed
wrteam-vimal opened this issue Oct 3, 2023 · 4 comments
Closed

Issue in library #439

wrteam-vimal opened this issue Oct 3, 2023 · 4 comments

Comments

@wrteam-vimal
Copy link

Steps to create issue

  1. Clone git code from given below link
  2. run flutter pub get
  3. run the flutter app into device
  4. Once app open, click on ”Voice to Text” button
  5. Click on Initialize button
  6. Click on Start
  7. Speak anything or leave it blank do not speak anything
  8. Go back
  9. Again, click on ”Voice to Text” button
  10. Click on Initialize button
  11. Click on start button
  12. Do not speak anything
  13. In log error will occur as below I attached

Video Link for produce the issue

Github Code Link

*Flutter log
E/flutter (23997): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: setState() called after dispose(): _VoiceToTextScreenState#fc8d9(lifecycle state: defunct, not mounted)
E/flutter (23997): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter (23997): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/flutter (23997): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
E/flutter (23997): #0 State.setState. (package:flutter/src/widgets/framework.dart:1102:9)
E/flutter (23997): #1 State.setState (package:flutter/src/widgets/framework.dart:1137:6)
E/flutter (23997): #2 _VoiceToTextScreenState.errorListener (package:speech_to_text_demo/voiceToTextScreen.dart:184:5)
E/flutter (23997): #3 SpeechToText._onNotifyError (package:speech_to_text/speech_to_text.dart:646:21)
E/flutter (23997): #4 MethodChannelSpeechToText._handleCallbacks (package:speech_to_text_platform_interface/method_channel_speech_to_text.dart:135:19)
E/flutter (23997): #5 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:547:55)
E/flutter (23997): #6 MethodChannel.setMethodCallHandler. (package:flutter/src/services/platform_channel.dart:540:34)
E/flutter (23997): #7 _DefaultBinaryMessenger.setMessageHandler. (package:flutter/src/services/binding.dart:567:35)
E/flutter (23997): #8 _invoke2 (dart:ui/hooks.dart:202:13)
E/flutter (23997): #9 _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45:5)
E/flutter (23997): #10 _Channel.push (dart:ui/channel_buffers.dart:135:31)
E/flutter (23997): #11 ChannelBuffers.push (dart:ui/channel_buffers.dart:331:17)
E/flutter (23997): #12 PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:736:22)
E/flutter (23997): #13 _dispatchPlatformMessage (dart:ui/hooks.dart:114:31)

@sowens-csd
Copy link
Contributor

Is this happening with the sample app or with your code? It looks like a Flutter usage issue not a speech plugin issue.

@wrteam-vimal
Copy link
Author

Is this happening with the sample app or with your code? It looks like a Flutter usage issue not a speech plugin issue.

@sowens-csd sir, We are using same code as well in second screen but when we get back and again initialize and again start speech and wait without any speech its get crash as I shared above.

@wrteam-vimal
Copy link
Author

@sowens-csd sir, Please check proper flow in attached video you will get better proper flow how it is crashing.

@sowens-csd
Copy link
Contributor

From the error stack it looks like you're calling setState in response to an error notification from speech to text. However, you're doing it after the widget has been disposed. You can check if the widget is mounted if it is stateful and if not don't make the setState call.

However, that's a local fix to a problem that shouldn't happen. It's better to make the error and status handlers global rather than tie them to a particular form. You should only initialize speech to text once for the lifetime of the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants