Skip to content
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

[Discussions] Selection Text #86

Closed
dath7 opened this issue Jul 19, 2024 · 4 comments
Closed

[Discussions] Selection Text #86

dath7 opened this issue Jul 19, 2024 · 4 comments
Assignees

Comments

@dath7
Copy link

dath7 commented Jul 19, 2024

Content

Content

Hi,
I use flutter_scrollview_observer for rendering list messages, and my case is after i select some texts and new message appear, the selection of text lost.

I have followed wiki.

I think the problem is my reversed list. Can you give me some recommend to solve this problem ? Thanks a lot.

My snippet code below:

ListViewObserver(
      controller: observerController,
      child:CustomSelectionArea(
            child: ListView.builder(
              physics: ChatObserverClampingScrollPhysics(observer: chatObserver),
              shrinkWrap: true,
              controller: widget.scrollController,
              reverse: true,
              itemCount: data.length,
              itemBuilder: (context, index) {
                  final message = data[index];
                  return ChatItem(message: message)
              }))
@LinXunFeng
Copy link
Member

This should be a bug of SelectionArea.
Related issue: flutter/flutter#124787

@dath7
Copy link
Author

dath7 commented Jul 22, 2024

Sorry for my late reply.
I think that related issue isn't same as my case. In my case, when new item appears, it's inserted at 0 so entire list has to rebuild and the selection of item lost.

Can you give me some recommend to solve this problem? Thanks a lot.

Example
Screen.Recording.2024-07-22.at.08.17.00.mov

@LinXunFeng
Copy link
Member

I think you can pause the update of ListView when selecting text.

bool canUpdateListView = true;

Widget resultWidget = ChatItemWidget(
  ...
);
resultWidget = SelectionArea(
  child: resultWidget,
  onSelectionChanged: (value) {
    canUpdateListView = value?.plainText == null;
    // The text is no longer selected. Update the ListView to display all the latest messages.
    if (canUpdateListView) {
      setState(() {});
    }
  },
);
return resultWidget;
_addMessage(int count) {
  chatObserver.standby(changeCount: count);
  needIncrementUnreadMsgCount = true;
  for (var i = 0; i < count; i++) {
    chatModels.insert(0, ChatDataHelper.createChatModel());
  }

  // Currently selecting text.
  if (!canUpdateListView) return;
  setState(() {});
}

@dath7
Copy link
Author

dath7 commented Jul 23, 2024

Let me try.
Thanks a lot!

@dath7 dath7 closed this as completed Jul 25, 2024
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

No branches or pull requests

3 participants