fluttercommunity / flutter-draggable-scrollbar

Draggable Scrollbar - A scrollbar that can be dragged for quickly navigation through a vertical list. Additional option is showing label next to scrollthumb with information about current item. Maintainer: @marica27
https://pub.dev/packages/draggable_scrollbar
MIT License
441 stars 78 forks source link

Dynamic scroll height #41

Open Marek00Malik opened 3 years ago

Marek00Malik commented 3 years ago

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

azmasamy commented 3 years ago

Facing the same issue, any news on this?

hendrickpras commented 2 years ago

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());
}
reynirf commented 2 years ago

@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?

RWaintrob commented 1 year ago

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