Skip to content

Commit 4501ab7

Browse files
authored
Merge pull request #31 from phiwu/develop
added onDoubleTap and onLongPress gestures
2 parents dde1cd1 + 0818501 commit 4501ab7

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lib/src/swiper.dart

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'package:flutter_swiper/flutter_swiper.dart';
44
import 'dart:async';
55

66
typedef void SwiperOnTap(int index);
7+
typedef void SwiperOnDoubleTap(int index);
8+
typedef void SwiperOnLongPress(int index);
79

810
typedef Widget SwiperDataBuilder(BuildContext context, dynamic data, int index);
911

@@ -73,6 +75,12 @@ class Swiper extends StatefulWidget {
7375
///Called when tap
7476
final SwiperOnTap onTap;
7577

78+
///Called when double tap
79+
final SwiperOnDoubleTap onDoubleTap;
80+
81+
///Called when long press
82+
final SwiperOnLongPress onLongPress;
83+
7684
///The swiper pagination plugin
7785
final SwiperPlugin pagination;
7886

@@ -111,6 +119,8 @@ class Swiper extends StatefulWidget {
111119
this.onIndexChanged,
112120
this.index,
113121
this.onTap,
122+
this.onDoubleTap,
123+
this.onLongPress,
114124
this.control,
115125
this.loop: true,
116126
this.curve: Curves.ease,
@@ -142,6 +152,8 @@ class Swiper extends StatefulWidget {
142152
ValueChanged<int> onIndexChanged,
143153
int index,
144154
SwiperOnTap onTap,
155+
SwiperOnDoubleTap onDoubleTap,
156+
SwiperOnLongPress onLongPress,
145157
bool loop: true,
146158
Curve curve: Curves.ease,
147159
Axis scrollDirection: Axis.horizontal,
@@ -179,6 +191,8 @@ class Swiper extends StatefulWidget {
179191
onIndexChanged: onIndexChanged,
180192
index: index,
181193
onTap: onTap,
194+
onDoubleTap: onDoubleTap,
195+
onLongPress: onLongPress,
182196
curve: curve,
183197
scrollDirection: scrollDirection,
184198
pagination: pagination,
@@ -206,6 +220,8 @@ class Swiper extends StatefulWidget {
206220
ValueChanged<int> onIndexChanged,
207221
int index,
208222
SwiperOnTap onTap,
223+
SwiperOnDoubleTap onDoubleTap,
224+
SwiperOnLongPress onLongPress,
209225
bool loop: true,
210226
Curve curve: Curves.ease,
211227
Axis scrollDirection: Axis.horizontal,
@@ -240,6 +256,8 @@ class Swiper extends StatefulWidget {
240256
onIndexChanged: onIndexChanged,
241257
index: index,
242258
onTap: onTap,
259+
onDoubleTap: onDoubleTap,
260+
onLongPress: onLongPress,
243261
curve: curve,
244262
key: key,
245263
scrollDirection: scrollDirection,
@@ -360,7 +378,13 @@ class _SwiperState extends _SwiperTimerMixin {
360378
return GestureDetector(
361379
behavior: HitTestBehavior.opaque,
362380
onTap: () {
363-
this.widget.onTap(index);
381+
this.widget.onTap?.call(index);
382+
},
383+
onDoubleTap: () {
384+
this.widget.onDoubleTap?.call(index);
385+
},
386+
onLongPress: () {
387+
this.widget.onLongPress?.call(index);
364388
},
365389
child: widget.itemBuilder(context, index),
366390
);
@@ -397,7 +421,7 @@ class _SwiperState extends _SwiperTimerMixin {
397421

398422
Widget _buildSwiper() {
399423
IndexedWidgetBuilder itemBuilder;
400-
if (widget.onTap != null) {
424+
if (widget.onTap != null || widget.onDoubleTap != null || widget.onLongPress != null) {
401425
itemBuilder = _wrapTap;
402426
} else {
403427
itemBuilder = widget.itemBuilder;

0 commit comments

Comments
 (0)