return MaterialApp(
title: 'Stream Chat Core Example',
home: HomeScreen(),
builder: (context, child) => StreamChatCore(
client: client,
child: child ?? const SizedBox.shrink(),
),
);Chat Client
StreamChatCore is a version of StreamChat found in stream_chat_flutter that is decoupled from
theme and initialisations.
Find the pub.dev documentation here
StreamChatCore is used to provide information about the chat client to the widget tree.
This Widget is used to react to life cycle changes and system updates.
When the app goes into the background, the websocket connection is kept alive for backgroundKeepAlive (default Duration(seconds: 15)). If the app stays in the background longer than that, the connection is closed; it is reopened when the app returns to the foreground.
Like the StreamChat widget in the higher level UI package, the StreamChatCore widget should
be on the top level before using any Stream functionality:
State recovery on reconnect
By default, the LLC (stream_chat) re-runs all active queries whenever the WebSocket reconnects (client.recoverStateOnReconnect = true). StreamChatCore overrides this to false on mount because the list controllers in stream_chat_flutter_core — StreamChannelListController, StreamMessageListController, and others — already refresh themselves when they receive a connectionRecovered event. Leaving LLC recovery on would cause a duplicate queryChannels round-trip.
If you use StreamChatCore without those controllers, for example when deep-linking directly into a single channel screen, you are responsible for refreshing the channel state on reconnect:
final subscription = client.on(EventType.connectionRecovered).listen((_) {
channel.watch();
});Cancel the subscription in your widget's dispose to avoid leaks.