I'm creating an application with chat functionality and I'm using Stream Chat Flutter. I followed the official tutorial: https://getstream.io/chat/flutter/tutorial/
The tutorial says to use the builder in MaterialApp and wrap the child route with StreamChat.
return MaterialApp(
builder: (context, widget) {
return StreamChat(
client: client,
child: widget,
);
},
home: StreamChannel(
channel: channel,
child: const ChannelPage(),
),
);
And to then call client.connectUser.
I want to know how I can efficiently disconnect and reconnect a user and make sure the web socket connections are closed, without wrapping my whole application with StreamChat.
Most of the Stream examples show how to initialise and connect users for the whole application and then they stay connected. But I only want to initialise and connect to Stream when the chat portion of the app is opened.