Skip to content

Commit

Permalink
fix: 🐛 dispose all ValueNotifiers and ScrollControllers in ChatContro…
Browse files Browse the repository at this point in the history
…ller.
  • Loading branch information
jonasbadstuebner authored and aditya-css committed Jun 19, 2024
1 parent b005e55 commit e8f7204
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
error when using `BuildContext` or `State` extensions when not mounted.
* **Fix**: [192](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/192) Fix
send to closed socket or animate on `ScrollController` without clients.
* **Fix**: [194](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/194) Dispose
all `ValueNotifier`s and `ScrollController`s in `ChatController`.

## [1.3.1]

Expand Down
14 changes: 10 additions & 4 deletions lib/src/controller/chat_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import 'dart:async';

import 'package:chatview/src/widgets/suggestions/suggestion_list.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import '../models/models.dart';
Expand All @@ -41,7 +42,7 @@ class ChatController {
/// chatcontroller.typingIndicatorNotifier.addListener((){});
/// ```
/// For more functionalities see [ValueNotifier].
ValueNotifier<bool> get typingIndicatorNotifier => _showTypingIndicator;
ValueListenable<bool> get typingIndicatorNotifier => _showTypingIndicator;

/// Allow user to add reply suggestions defaults to empty.
final ValueNotifier<List<SuggestionItemData>> _replySuggestion =
Expand All @@ -53,7 +54,7 @@ class ChatController {
/// chatcontroller.newSuggestions.addListener((){});
/// ```
/// For more functionalities see [ValueNotifier].
ValueNotifier<List<SuggestionItemData>> get newSuggestions =>
ValueListenable<List<SuggestionItemData>> get newSuggestions =>
_replySuggestion;

/// Getter for typingIndicator value instead of accessing [_showTypingIndicator.value]
Expand Down Expand Up @@ -83,8 +84,13 @@ class ChatController {
/// Represents message stream of chat
StreamController<List<Message>> messageStreamController = StreamController();

/// Used to dispose stream.
void dispose() => messageStreamController.close();
/// Used to dispose ValueNotifiers and Streams.
void dispose() {
_showTypingIndicator.dispose();
_replySuggestion.dispose();
scrollController.dispose();
messageStreamController.close();
}

/// Used to add message in message list.
void addMessage(Message message) {
Expand Down

0 comments on commit e8f7204

Please sign in to comment.