flutter-draggable-scrollbar icon indicating copy to clipboard operation
flutter-draggable-scrollbar copied to clipboard

Dynamic scroll height

Open Marek00Malik opened this issue 4 years ago • 4 comments

Hello, First thing, great work guys!

I would like to ask about the possibility of adding/making the scroll calculated dynamically depending on the number of items needed to be scrolled throw. When the list of items changes (increases or decreases), the scrollbar does not change - both its height and position.

This could also help to fix this issue that is already raised: https://github.com/fluttercommunity/flutter-draggable-scrollbar/issues/32

Marek00Malik avatar Dec 13 '20 22:12 Marek00Malik

Facing the same issue, any news on this?

azmasamy avatar Jan 03 '21 12:01 azmasamy

This workaround might help for now. The ScrollController needs jumping to top and bottom, then it recognize the updated ListView's children height. The 200 ms duration gives time for widget to rebuild.

late ScrollController _controller;
...

@override
Widget build(_) {
    return ...
    DraggableScrollbar.semicircle(child: ListView(children: [], controller: _controller), controller: _controller)
    ...
}

void _calibrateScrollbarPosition() {
    final double offset = _controller.offset;
    _controller.jumpTo(0.0);
    _controller.jumpTo(_controller.position.maxScrollExtent);
    _controller.jumpTo(offset);
}

@override
void dispose() {
    _controller.dispose();
    ...
    super.dispose();
}

@override
void initState() {
    super.initState();
    _controller = ScrollController();
    ...
}

void _triggerChangeContent() {
    ...
    setState((){});
    Future.delayed(Duration(milliseconds: 200), () => _calibrateScrollbarPosition());
}

hendrickpras avatar Sep 16 '21 10:09 hendrickpras

@hendrickpras This only works if you scroll by swiping, but if I use the semicircle (thumb) to scroll, it doesn't jump. Have you found any other solution to this issue?

reynirf avatar Dec 07 '21 14:12 reynirf

I need that when I find a certain text that I enter in the search (that I built) It automatically scrolls there Thanck

RWaintrob avatar May 21 '23 08:05 RWaintrob