diff --git a/lib/src/swiper.dart b/lib/src/swiper.dart index 2221c24..8d8cfa0 100644 --- a/lib/src/swiper.dart +++ b/lib/src/swiper.dart @@ -4,6 +4,8 @@ import 'package:flutter_swiper/flutter_swiper.dart'; import 'dart:async'; typedef void SwiperOnTap(int index); +typedef void SwiperOnDoubleTap(int index); +typedef void SwiperOnLongPress(int index); typedef Widget SwiperDataBuilder(BuildContext context, dynamic data, int index); @@ -73,6 +75,12 @@ class Swiper extends StatefulWidget { ///Called when tap final SwiperOnTap onTap; + ///Called when double tap + final SwiperOnDoubleTap onDoubleTap; + + ///Called when long press + final SwiperOnLongPress onLongPress; + ///The swiper pagination plugin final SwiperPlugin pagination; @@ -111,6 +119,8 @@ class Swiper extends StatefulWidget { this.onIndexChanged, this.index, this.onTap, + this.onDoubleTap, + this.onLongPress, this.control, this.loop: true, this.curve: Curves.ease, @@ -142,6 +152,8 @@ class Swiper extends StatefulWidget { ValueChanged onIndexChanged, int index, SwiperOnTap onTap, + SwiperOnDoubleTap onDoubleTap, + SwiperOnLongPress onLongPress, bool loop: true, Curve curve: Curves.ease, Axis scrollDirection: Axis.horizontal, @@ -179,6 +191,8 @@ class Swiper extends StatefulWidget { onIndexChanged: onIndexChanged, index: index, onTap: onTap, + onDoubleTap: onDoubleTap, + onLongPress: onLongPress, curve: curve, scrollDirection: scrollDirection, pagination: pagination, @@ -206,6 +220,8 @@ class Swiper extends StatefulWidget { ValueChanged onIndexChanged, int index, SwiperOnTap onTap, + SwiperOnDoubleTap onDoubleTap, + SwiperOnLongPress onLongPress, bool loop: true, Curve curve: Curves.ease, Axis scrollDirection: Axis.horizontal, @@ -240,6 +256,8 @@ class Swiper extends StatefulWidget { onIndexChanged: onIndexChanged, index: index, onTap: onTap, + onDoubleTap: onDoubleTap, + onLongPress: onLongPress, curve: curve, key: key, scrollDirection: scrollDirection, @@ -360,7 +378,13 @@ class _SwiperState extends _SwiperTimerMixin { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - this.widget.onTap(index); + this.widget.onTap?.call(index); + }, + onDoubleTap: () { + this.widget.onDoubleTap?.call(index); + }, + onLongPress: () { + this.widget.onLongPress?.call(index); }, child: widget.itemBuilder(context, index), ); @@ -397,7 +421,7 @@ class _SwiperState extends _SwiperTimerMixin { Widget _buildSwiper() { IndexedWidgetBuilder itemBuilder; - if (widget.onTap != null) { + if (widget.onTap != null || widget.onDoubleTap != null || widget.onLongPress != null) { itemBuilder = _wrapTap; } else { itemBuilder = widget.itemBuilder;