skip to Main Content

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

2

Answers


  1. Try wrapping the code with this:

    if(mounted)  {
     /* code */
     }
    

    and see what it will show!

    Login or Signup to reply.
  2. 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:....
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search