Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show scrollbar in SliverList?

I'm using SliverAppBar and SliverList as main containers in my app. When I try to wrap SliverList in Scrollbar widget, I get an error, and when I wrap whole CustomScrollView in Scrollbar, it overlaps SliverAppBar. So how can I show scrollbar indicator only in my SliverList? Thanks in advance.

like image 637
emvaized Avatar asked Jun 18 '19 00:06

emvaized


People also ask

How do you use a SliverList in Flutter?

Dart. The SliverStack() allows putting one sliver on another. In the below example, through SliverPositioned() we are creating the complete layout of yellow color on top of which we are rendering list items using SliverList(). SliverList() takes a delegate as a parameter to give the items to the list to be scrolled.

How do you use a sliver?

How to use slivers? It is to note that all of the sliver's components should always be placed inside a CustomScrollView. After that, we can combine the list of slivers to make the custom scrollable area.


2 Answers

Check out @JLarana's answer at https://stackoverflow.com/a/62938436/10647220

But basically what you need to do is:

ScrollController _scrollController = ScrollController();
...
body: PrimaryScrollController(
    controller: _scrollController,
        child: CupertinoScrollbar(
            child: CustomScrollView(
                slivers:[
                    your slivers code here
                 ]
like image 155
Luan Träsel Avatar answered Sep 22 '22 19:09

Luan Träsel


If I understand your question correctly... as of Flutter 1.12 released in Dec 2019, I think this issue is currently tracked under

https://github.com/flutter/flutter/issues/13253

I'm not aware of a easy solution for this(maybe NestedScrollView will solve your problem, but it has some subtle fidelity issues so I don't want to use).

like image 44
edward Avatar answered Sep 20 '22 19:09

edward