Home > OS >  Flutter Error : Consider canceling any active work during "dispose" or using the "mou
Flutter Error : Consider canceling any active work during "dispose" or using the "mou

Time:11-21

I am using bloc state management in the Flutter framework, and I am working on an application that uses a socket with chat. I want as soon as the user leaves the room, I send an event to the socket so that he leaves the chat, but I see the error attached to you in the address, what is the solution?

Where I call method leave room

CodePudding user response:

Try wrapping the code with this:

if(mounted)  {
 /* code */
 }

and see what it will show!

CodePudding user response:

Have you tried to warp this screen with WillPopScope. There is a function to execute an action before user go back

WillPopScope(
  onWillPop: () {
    AppCubit.get(context).leaveRoom(widget.chatID);
    return true;
  }, 
  child:....
)
  • Related