Skip to content

Commit

Permalink
Merge pull request #8 from matthewrice345/ImplementMoveFunctionality
Browse files Browse the repository at this point in the history
Adds functionality to use IndexController.MOVE for custom_layout
  • Loading branch information
TheAnkurPanchani authored Nov 30, 2021
2 parents 8851b60 + 74a46ff commit 4322bae
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/src/custom_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
return index;
}

int _moveIndex() {
final index = widget.controller!.index ?? _currentIndex;
if(!widget.loop! && index >= widget.itemCount! - 1) {
return widget.itemCount! - 1;
} else if(!widget.loop! && index < 0) {
return 0;
}
return index;
}

int _prevIndex() {
final index = _currentIndex - 1;
if (!widget.loop! && index < 0) {
Expand All @@ -185,8 +195,10 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
_move(0.0, nextIndex: nextIndex);
break;
case IndexController.MOVE:
throw Exception(
'Custom layout does not support SwiperControllerEvent.MOVE_INDEX yet!');
var moveIndex = _moveIndex();
if (moveIndex == _currentIndex) return;
_move(moveIndex > _currentIndex ? 1.0 : 0.0, nextIndex: moveIndex);
break;
case SwiperController.STOP_AUTOPLAY:
case SwiperController.START_AUTOPLAY:
break;
Expand Down

0 comments on commit 4322bae

Please sign in to comment.