Skip to content

fix: ScrollController is disposed when parent widget state changes (#289) #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lhengl
Copy link

@lhengl lhengl commented May 14, 2025

Description

This PR fixes a lifecycle issue where ChatListWidget improperly disposes the ScrollController provided via the external ChatController.

Currently, ChatController.scrollController is passed into the widget tree and used in multiple places, including pagination and scrolling logic. However, the ChatListWidget calls scrollController.dispose() in its dispose() method — even though it did not create the controller.

This causes runtime exceptions (ScrollController was disposed) when parent widgets rebuild and reuse the same controller, which is a valid and supported use case.

This PR changes:

  • Removes the call to scrollController.dispose() and chatController.messageStreamController.close() from ChatListWidget.dispose()
  • Ensures that the responsibility of disposing shared resources remains with the owning class (i.e., ChatController)

No behavior changes, just safer lifecycle management.

Checklist

  • The title of my PR starts with a [Conventional Commit] prefix (fix:).
  • I have followed the [Contributor Guide] when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

(Tests/docs not updated because the fix affects lifecycle behavior, not exposed API.)

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

N/A, but may be related to general lifecycle issues encountered by users embedding ChatView in reactive widget trees (e.g. GetX, Riverpod).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant