diff --git a/lib/widget.dart b/lib/widget.dart index 73d83c9..f9da33e 100644 --- a/lib/widget.dart +++ b/lib/widget.dart @@ -1,12 +1,13 @@ import 'dart:async'; +import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import './render.dart'; +import 'models/alignments.dart'; import 'models/sticky_state.dart'; import 'models/types.dart'; -import 'models/alignments.dart'; typedef InfiniteListItem ItemBuilder(BuildContext context, I index); @@ -228,6 +229,15 @@ class InfiniteList extends StatefulWidget { /// Proxy property for [ScrollView.physics] final ScrollPhysics physics; + /// Additional slivers to be placed before the list. + final List sliversBefore; + + /// Additional slivers to be placed after the list. + final List sliversAfter; + + /// Divider. + final Widget divider; + final Key _centerKey; InfiniteList({ @@ -242,6 +252,9 @@ class InfiniteList extends StatefulWidget { this.cacheExtent, this.scrollDirection = Axis.vertical, this.physics, + this.sliversBefore = const [], + this.sliversAfter = const [], + this.divider, }) : _centerKey = (direction == InfiniteListDirection.multi) ? UniqueKey() : null, super(key: key); @@ -265,30 +278,35 @@ class _InfiniteListState extends State { SliverList get _forwardList => SliverList( delegate: SliverChildBuilderDelegate( _buildListItem, - childCount: widget.posChildCount, + childCount: widget.posChildCount * 2 - 1, ), key: widget._centerKey, ); - Widget _buildListItem(BuildContext context, int index) => - _StickySliverListItem( - streamController: _streamController, - index: index, - listItem: widget.builder(context, index), - ); + Widget _buildListItem(BuildContext context, int index) => index.isEven + ? _StickySliverListItem( + streamController: _streamController, + index: index, + listItem: widget.builder(context, index ~/ 2), + ) + : widget.divider; - List get _slivers { + List get _slivers { switch (widget.direction) { case InfiniteListDirection.multi: return [ + ...widget.sliversBefore, _reverseList, _forwardList, + ...widget.sliversAfter, ]; case InfiniteListDirection.single: default: return [ + ...widget.sliversBefore, _forwardList, + ...widget.sliversAfter, ]; } } diff --git a/pubspec.yaml b/pubspec.yaml index f8b34c5..31c1f01 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ repository: https://github.com/TatsuUkraine/flutter_sticky_infinite_list issue_tracker: https://github.com/TatsuUkraine/flutter_sticky_infinite_list/issues environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.2.2 <3.0.0" flutter: ">=1.20.0-2.0.pre" dependencies: