SimformSolutionsPvtLtd / flutter_chatview

Highly customisable chat UI with reply and reaction functionality.
https://pub.dev/packages/chatview
MIT License
296 stars 131 forks source link

Clear initial message list - Exception Widget's Ancestor is unsafe #238

Closed kkruel8100 closed 1 month ago

kkruel8100 commented 1 month ago

Describe the bug Unable to clear the initial list. Need ability for user to clear the initial list and start a chat from fresh.

Approach 1: Created method clearItems Added button to app bar When button is clicked, the clear items is called. it sets the chatController.initialMessageList = [] chatViewState = ChatViewState.noData

Expected results: Clears the list, displays noMessage Widget, and error free

Actual results: Clears the list and displays noMessage Widget with exceptions. Stack trace shows that after updating the chatViewState

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown while finalizing the widget tree: Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.

packages/chatview/src/widgets/chat_view_inherited_widget.dart 23:14 of packages/chatview/src/extensions/extensions.dart 134:41 StatefulWidgetExtension.get$35chatViewIW packages/chatview/src/widgets/chat_list_widget.dart 249:5 dispose

So the errors appear to be occurring in the chatview source files.

Approach 2: Remove line chatViewState = ChatViewState.noData

Actual results: Clears the list with no exceptions. But the noMessageWidget does not appear.

Approach 3: Change to sequence chatViewState = ChatViewState.noData chatController.initialMessageList = []

Actual results: Same as approach 1

The errors and stack trace are directly related to updating the chatViewState.

How can I allow the user to clear the list and then update the state to show the no message widget without errors?

Any documentation or guidance is much appreciated to resolve this issue.

Thank you.

kkruel8100 commented 1 month ago

I have some additional information to supply. I discovered yesterday that my system updated to 2.1.0 automatically. Two things happened on that update.

  1. The issue that I describe above where I can no longer update to ChatViewState.noData
  2. The outgoing bubbles shifted to the left of the screen in the same position as the incoming bubbles

I have temporarily downgraded back to 2.0.0 which resolves the issues experienced in 2.0.0.

This will prevent me from updating the app so the issue remains open and would need to be addressed.

vatsaltanna commented 1 month ago

Hi @kkruel8100 , it will be easy for us to investigate this issue if you can provide reproducible sample code.

rain3k commented 1 month ago

@kkruel8100 Thank you so much! I was really struggling with this problem and spent three hours on it. I was exhausted, but then I saw your comment. I tried downgrading the version, and it resolved the issue! Thanks again!