Reputation: 598
A Simple example would be:
Scaffold(
floatingActionButton: _fab(),
floatingActionButtonLocation: _fabLocation(),
body: Scrollbar(
child: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
automaticallyImplyLeading: false,
leading: null,
backgroundColor: Theme.of(context).colorScheme.secondary,
title: AutoSizeText(
_catalogSearchRatio,
style: Theme.of(context).textTheme.title.copyWith(
color: Theme.of(context).colorScheme.onSecondary),
),
floating: true,
pinned: false,
),
SliverFixedExtentList(
itemExtent: 90.0,
delegate: SliverChildBuilderDelegate((context, index) {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 5.0, vertical: 5.0),
child: CatalogItems.medidaGroups
.contains(_itemsCatalogDisplay[index].group)
? _medidasCard(
index, _itemsCatalogDisplay, _catalogSearchQuery)
: _catalogCard(index, _itemsCatalogDisplay,
_catalogSearchQuery, _cartItems, _filteredGroups),
);
}, childCount: itemsCatalogDisplayLength),
),
],
controller: _catalogScrollController,
),
),
);
In the above example, a Scrollbar can be used and that's fine. BUT you can't drag the scrollbar. So I am using a package called draggable_scrollbar which lets me drag the scrollbar. However, I can't seem to replace the scrollbar I have in the example because it gives me the can't be assigned to BoxScrollView error. It works if it's just a Listview or a Listview.builder or even a GridView
Upvotes: 2
Views: 4389
Reputation: 51
Start by importing the Cupertino
package like below..
Import 'package: flutter/cupertino.dart';
Now, inside your class which contains your ScrollViews
add the ScrollController
like below...
final ScrollController myScrollWorks = ScrollController();
Now wrap any of your ScrollViews
... which in your case is a CustomScrollView
with the code below
body: PrimaryScrollController(
controller: myScrollWorks,
child: CupertinoScrollbar(
child: CustomScrollView(
slivers:[
your slivers code here
];
Upvotes: 2