|
@@ -62,6 +62,8 @@ class HugeListView<T> extends StatefulWidget {
|
|
|
|
|
|
final bool disableScroll;
|
|
|
|
|
|
+ final bool isScrollablePositionedList;
|
|
|
+
|
|
|
const HugeListView({
|
|
|
Key? key,
|
|
|
this.controller,
|
|
@@ -80,6 +82,7 @@ class HugeListView<T> extends StatefulWidget {
|
|
|
this.isDraggableScrollbarEnabled = true,
|
|
|
this.thumbPadding,
|
|
|
this.disableScroll = false,
|
|
|
+ this.isScrollablePositionedList = true,
|
|
|
}) : super(key: key);
|
|
|
|
|
|
@override
|
|
@@ -96,7 +99,9 @@ class HugeListViewState<T> extends State<HugeListView<T>> {
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
|
|
|
- listener.itemPositions.addListener(_sendScroll);
|
|
|
+ widget.isScrollablePositionedList
|
|
|
+ ? listener.itemPositions.addListener(_sendScroll)
|
|
|
+ : null;
|
|
|
}
|
|
|
|
|
|
@override
|
|
@@ -131,47 +136,56 @@ class HugeListViewState<T> extends State<HugeListView<T>> {
|
|
|
return widget.emptyResultBuilder!(context);
|
|
|
}
|
|
|
|
|
|
- return DraggableScrollbar(
|
|
|
- key: scrollKey,
|
|
|
- totalCount: widget.totalCount,
|
|
|
- initialScrollIndex: widget.startIndex,
|
|
|
- onChange: (position) {
|
|
|
- final int currentIndex = _currentFirst();
|
|
|
- final int floorIndex = (position * widget.totalCount).floor();
|
|
|
- final int cielIndex = (position * widget.totalCount).ceil();
|
|
|
- int nextIndexToJump;
|
|
|
- if (floorIndex != currentIndex && floorIndex > currentIndex) {
|
|
|
- nextIndexToJump = floorIndex;
|
|
|
- } else if (cielIndex != currentIndex && cielIndex < currentIndex) {
|
|
|
- nextIndexToJump = floorIndex;
|
|
|
- } else {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (lastIndexJump != nextIndexToJump) {
|
|
|
- lastIndexJump = nextIndexToJump;
|
|
|
- widget.controller?.jumpTo(index: nextIndexToJump);
|
|
|
- }
|
|
|
- },
|
|
|
- labelTextBuilder: widget.labelTextBuilder,
|
|
|
- backgroundColor: widget.thumbBackgroundColor,
|
|
|
- drawColor: widget.thumbDrawColor,
|
|
|
- heightScrollThumb: widget.thumbHeight,
|
|
|
- bottomSafeArea: widget.bottomSafeArea,
|
|
|
- currentFirstIndex: _currentFirst(),
|
|
|
- isEnabled: widget.isDraggableScrollbarEnabled,
|
|
|
- padding: widget.thumbPadding,
|
|
|
- child: ScrollablePositionedList.builder(
|
|
|
- physics:
|
|
|
- widget.disableScroll ? const NeverScrollableScrollPhysics() : null,
|
|
|
- itemScrollController: widget.controller,
|
|
|
- itemPositionsListener: listener,
|
|
|
- initialScrollIndex: widget.startIndex,
|
|
|
- itemCount: max(widget.totalCount, 0),
|
|
|
- itemBuilder: (context, index) {
|
|
|
- return widget.itemBuilder(context, index);
|
|
|
- },
|
|
|
- ),
|
|
|
- );
|
|
|
+ return widget.isScrollablePositionedList
|
|
|
+ ? DraggableScrollbar(
|
|
|
+ key: scrollKey,
|
|
|
+ totalCount: widget.totalCount,
|
|
|
+ initialScrollIndex: widget.startIndex,
|
|
|
+ onChange: (position) {
|
|
|
+ final int currentIndex = _currentFirst();
|
|
|
+ final int floorIndex = (position * widget.totalCount).floor();
|
|
|
+ final int cielIndex = (position * widget.totalCount).ceil();
|
|
|
+ int nextIndexToJump;
|
|
|
+ if (floorIndex != currentIndex && floorIndex > currentIndex) {
|
|
|
+ nextIndexToJump = floorIndex;
|
|
|
+ } else if (cielIndex != currentIndex &&
|
|
|
+ cielIndex < currentIndex) {
|
|
|
+ nextIndexToJump = floorIndex;
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (lastIndexJump != nextIndexToJump) {
|
|
|
+ lastIndexJump = nextIndexToJump;
|
|
|
+ widget.controller?.jumpTo(index: nextIndexToJump);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ labelTextBuilder: widget.labelTextBuilder,
|
|
|
+ backgroundColor: widget.thumbBackgroundColor,
|
|
|
+ drawColor: widget.thumbDrawColor,
|
|
|
+ heightScrollThumb: widget.thumbHeight,
|
|
|
+ bottomSafeArea: widget.bottomSafeArea,
|
|
|
+ currentFirstIndex: _currentFirst(),
|
|
|
+ isEnabled: widget.isDraggableScrollbarEnabled,
|
|
|
+ padding: widget.thumbPadding,
|
|
|
+ child: ScrollablePositionedList.builder(
|
|
|
+ physics: widget.disableScroll
|
|
|
+ ? const NeverScrollableScrollPhysics()
|
|
|
+ : null,
|
|
|
+ itemScrollController: widget.controller,
|
|
|
+ itemPositionsListener: listener,
|
|
|
+ initialScrollIndex: widget.startIndex,
|
|
|
+ itemCount: max(widget.totalCount, 0),
|
|
|
+ itemBuilder: (context, index) {
|
|
|
+ return widget.itemBuilder(context, index);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ : ListView.builder(
|
|
|
+ itemCount: max(widget.totalCount, 0),
|
|
|
+ itemBuilder: (context, index) {
|
|
|
+ return widget.itemBuilder(context, index);
|
|
|
+ },
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/// Jump to the [position] in the list. [position] is between 0.0 (first item) and 1.0 (last item), practically currentIndex / totalCount.
|