Skip to content

Commit

Permalink
Fix #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
deakjahn committed Feb 8, 2021
1 parent b5905e0 commit d3cfed2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.2] - 2021-02-08

* Fix #2 (https://github.com/deakjahn/huge_listview/issues/2).

## [1.0.1] - 2020-10-29

* Different scroll thumbs.
Expand Down
4 changes: 3 additions & 1 deletion lib/src/draggable_scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DraggableScrollbar extends StatefulWidget {
final EdgeInsetsGeometry padding;
final int totalCount;
final int initialScrollIndex;
final int currentFirstIndex;
final ValueChanged<double> onChange;
final ScrollThumbBuilder scrollThumbBuilder;

Expand All @@ -23,6 +24,7 @@ class DraggableScrollbar extends StatefulWidget {
this.padding,
this.totalCount = 1,
this.initialScrollIndex = 0,
this.currentFirstIndex = 0,
@required this.scrollThumbBuilder,
this.onChange,
}) : assert(child != null),
Expand Down Expand Up @@ -79,7 +81,7 @@ class DraggableScrollbarState extends State<DraggableScrollbar> with TickerProvi
alignment: Alignment.topRight,
margin: EdgeInsets.only(top: thumbOffset),
padding: widget.padding,
child: widget.scrollThumbBuilder?.call(widget.backgroundColor, widget.drawColor, widget.heightScrollThumb),
child: widget.scrollThumbBuilder?.call(widget.backgroundColor, widget.drawColor, widget.heightScrollThumb, widget.currentFirstIndex),
),
);

Expand Down
8 changes: 4 additions & 4 deletions lib/src/draggable_scrollbar_thumbs.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';

typedef ScrollThumbBuilder = Widget Function(Color backgroundColor, Color drawColor, double height);
typedef ScrollThumbBuilder = Widget Function(Color backgroundColor, Color drawColor, double height, int index);

class DraggableScrollbarThumbs {
static Widget RoundedRectThumb(Color backgroundColor, Color drawColor, double height) {
static Widget RoundedRectThumb(Color backgroundColor, Color drawColor, double height, int index) {
return Material(
elevation: 4.0,
child: Container(
Expand All @@ -14,7 +14,7 @@ class DraggableScrollbarThumbs {
);
}

static Widget ArrowThumb(Color backgroundColor, Color drawColor, double height) {
static Widget ArrowThumb(Color backgroundColor, Color drawColor, double height, int index) {
return ClipPath(
child: Container(
width: 20.0,
Expand All @@ -28,7 +28,7 @@ class DraggableScrollbarThumbs {
);
}

static Widget SemicircleThumb(Color backgroundColor, Color drawColor, double height) {
static Widget SemicircleThumb(Color backgroundColor, Color drawColor, double height, int index) {
return CustomPaint(
foregroundPainter: _ArrowCustomPainter(drawColor),
child: Material(
Expand Down
12 changes: 11 additions & 1 deletion lib/src/huge_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,20 @@ class HugeListViewState<T> extends State<HugeListView<T>> {
}

void _sendScroll() {
int current = listener.itemPositions.value.first.index;
int current = _currentFirst();
widget.firstShown?.call(current);
scrollKey.currentState?.setPosition(current / widget.totalCount);
}

int _currentFirst() {
try {
return listener.itemPositions.value.first.index;
}
catch (e) {
return 0;
}
}

@override
Widget build(BuildContext context) {
if (error != null && widget.errorBuilder != null) return widget.errorBuilder(context, error);
Expand All @@ -142,6 +151,7 @@ class HugeListViewState<T> extends State<HugeListView<T>> {
backgroundColor: widget.thumbBackgroundColor,
drawColor: widget.thumbDrawColor,
heightScrollThumb: widget.thumbHeight,
currentFirstIndex: _currentFirst(),
child: ScrollablePositionedList.builder(
itemScrollController: widget.controller,
itemPositionsListener: listener,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ packages:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4+1"
version: "2.1.5"
scrollable_positioned_list:
dependency: "direct main"
description:
name: scrollable_positioned_list
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.8"
version: "0.1.9"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: huge_listview
description: A performant list with any number of items.
version: 1.0.1
version: 1.0.2
homepage: https://github.com/deakjahn/huge_listview

environment:
Expand Down

0 comments on commit d3cfed2

Please sign in to comment.