Skip to content

Commit

Permalink
add scroll controller
Browse files Browse the repository at this point in the history
  • Loading branch information
vesuvi88 committed Aug 15, 2023
1 parent 90a58a5 commit a1bed26
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ScrollablePositionedList extends StatefulWidget {
required this.itemBuilder,
Key? key,
this.itemScrollController,
this.scrollController,
this.shrinkWrap = false,
ItemPositionsListener? itemPositionsListener,
this.scrollOffsetController,
Expand Down Expand Up @@ -73,6 +74,7 @@ class ScrollablePositionedList extends StatefulWidget {
Key? key,
this.shrinkWrap = false,
this.itemScrollController,
this.scrollController,
ItemPositionsListener? itemPositionsListener,
this.scrollOffsetController,
ScrollOffsetListener? scrollOffsetListener,
Expand All @@ -94,6 +96,8 @@ class ScrollablePositionedList extends StatefulWidget {
scrollOffsetNotifier = scrollOffsetListener as ScrollOffsetNotifier?,
super(key: key);

final ScrollController? scrollController;

/// Number of items the [itemBuilder] can produce.
final int itemCount;

Expand Down Expand Up @@ -405,6 +409,11 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>

@override
Widget build(BuildContext context) {
if (widget.scrollController?.positions.isEmpty == true)
WidgetsBinding.instance.addPostFrameCallback((_) {
widget.scrollController?.attach(primary.scrollController.position);
});

return LayoutBuilder(
builder: (context, constraints) {
final cacheExtent = _cacheExtent(constraints);
Expand Down Expand Up @@ -610,6 +619,9 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
if (mounted) {
setState(() {
if (opacity.value >= 0.5) {
if (widget.scrollController?.position != null) {
widget.scrollController?.detach(widget.scrollController!.position);
}
// Secondary [ListView] is more visible than the primary; make it the
// new primary.
var temp = primary;
Expand Down

0 comments on commit a1bed26

Please sign in to comment.