Skip to content

Commit 5fb4e14

Browse files
committed
Added dispose of feeds client
1 parent fd49c67 commit 5fb4e14

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/stream_feeds/lib/src/feeds_client.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FeedsClient {
2626
apiKey: apiKey,
2727
user: user,
2828
getToken: () async => userToken,
29-
getConnectionId: () => webSocketClient?.connectionId,
29+
getConnectionId: () => webSocketClient.connectionId,
3030
),
3131
),
3232
);
@@ -72,8 +72,8 @@ class FeedsClient {
7272
Future<void> connect() async {
7373
webSocketClient.connect();
7474

75-
_connectionSubscription = webSocketClient!.connectionStateStream
76-
.listen(_onConnectionStateChanged);
75+
_connectionSubscription =
76+
webSocketClient.connectionStateStream.listen(_onConnectionStateChanged);
7777

7878
connectionRecoveryHandler = DefaultConnectionRecoveryHandler(
7979
client: webSocketClient,
@@ -94,6 +94,13 @@ class FeedsClient {
9494
_connectionCompleter = null;
9595
}
9696

97+
void dispose() {
98+
if (webSocketClient.connectionState is Connected) {
99+
disconnect();
100+
}
101+
webSocketClient.dispose();
102+
}
103+
97104
void _onConnectionStateChanged(WebSocketConnectionState state) {
98105
if (_connectionCompleter != null) {
99106
if (state is Connected) {

sample_app/lib/navigation/app_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AppStateProvider extends ValueNotifier<AppState> {
4848
void clearUserId() {
4949
_prefs.remove('user_id');
5050
if (value is LoggedInState) {
51-
(value as LoggedInState).feedsClient.disconnect();
51+
(value as LoggedInState).feedsClient.dispose();
5252
}
5353
value = LoggedOutState();
5454
}

0 commit comments

Comments
 (0)