Search code examples
fluttersinglechildscrollview

Flutter - How can I dismiss SelectionControls when scrolling?


I am using SelectableText inside SingleChildScrollView.

SingleChildScrollView(
  child: Container(
    padding: const EdgeInsets.all(20.0),
    child: SelectableText(loremipsum),
  ),
);

In selectionControls, when I select the property named ToolBarItemControl.copy, chaos ensues. If you look at the video here, you can see the exact problem. How can I dismiss SelectionControls when scrolling?


Solution

  • For this, simply add keyboardDismissBehavior to SingleChildScrollView. Like this:

    SingleChildScrollView(
      keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
      child: Container(
        padding: const EdgeInsets.all(20.0),
        child: SelectableText(loremipsum),
      ),
    );