Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions lib/src/controller/auto_animated_sliver_list_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ class AutoAnimateSliverListController<T> {
_currentItems = newItems;

final provider = _tickerProvider;
if (provider == null) return;
if (provider == null) {
Future.microtask(() => _isAddingItem = false);
return;
}

// Create animation controller for new item
final moveController = AnimationController(
Expand Down Expand Up @@ -311,16 +314,17 @@ class AutoAnimateSliverListController<T> {
});
}

/// Do not use this method directly, use [updateItems]
/// Do not use this method directly
void updateItems(List<T> updatedItems) => _items = updatedItems;

/// Do not use this method directly, use [updateItemsWithAnimation]
/// Do not use this method directly
void updateItemsWithAnimation({
required TickerProvider tickerProvider,
required List<T> updatedItems,
bool forceUpdate = false,
}) {
this._tickerProvider = tickerProvider;
if (_isAddingItem || _isRemovingItem) return;
if (!forceUpdate && (_isAddingItem || _isRemovingItem)) return;

final newItems = List<T>.from(_items);
final newItemKeys = <String>{};
Expand Down Expand Up @@ -450,7 +454,7 @@ class AutoAnimateSliverListController<T> {
}

void initialize({required TickerProvider tickerProvider}) {
this._tickerProvider ??= tickerProvider;
this._tickerProvider = tickerProvider;

final currentItemsLength = _currentItems.length;
for (var i = 0; i < currentItemsLength; i++) {
Expand All @@ -474,4 +478,28 @@ class AutoAnimateSliverListController<T> {
values[i].moveController.dispose();
}
}

/// Do not use this method directly
/// Disposes all AnimationControllers and their tickers without disposing the controller itself.
void disposeAnimations() {
final values = _itemStates.values.toList();
final valuesLength = values.length;
for (var i = 0; i < valuesLength; i++) {
final controller = values[i].moveController;
controller
..stop()
..dispose();
}
// Clear the map to prevent reuse of disposed controllers
_itemStates.clear();
_itemKeys.clear();
_removingItems.clear();
_items.clear();
_currentItems = List<T>.from(_items);
_isNewItemAddedAtTop = false;
_newItemHeight = 0.0;
_isAddingItem = false;
_isRemovingItem = false;
_tickerProvider = null;
}
}
2 changes: 1 addition & 1 deletion lib/src/controller/chat_list_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ base class ChatViewListController {
/// making changes.
void removeChat(String chatId) {
if (!_chatListMap.containsKey(chatId) ||
!(_searchResultMap?.containsKey(chatId) ?? false)) {
!(_searchResultMap?.containsKey(chatId) ?? true)) {
return;
}
_searchResultMap?.remove(chatId);
Expand Down