@@ -4,6 +4,8 @@ import 'package:flutter_swiper/flutter_swiper.dart';
4
4
import 'dart:async' ;
5
5
6
6
typedef void SwiperOnTap (int index);
7
+ typedef void SwiperOnDoubleTap (int index);
8
+ typedef void SwiperOnLongPress (int index);
7
9
8
10
typedef Widget SwiperDataBuilder (BuildContext context, dynamic data, int index);
9
11
@@ -73,6 +75,12 @@ class Swiper extends StatefulWidget {
73
75
///Called when tap
74
76
final SwiperOnTap onTap;
75
77
78
+ ///Called when double tap
79
+ final SwiperOnDoubleTap onDoubleTap;
80
+
81
+ ///Called when long press
82
+ final SwiperOnLongPress onLongPress;
83
+
76
84
///The swiper pagination plugin
77
85
final SwiperPlugin pagination;
78
86
@@ -111,6 +119,8 @@ class Swiper extends StatefulWidget {
111
119
this .onIndexChanged,
112
120
this .index,
113
121
this .onTap,
122
+ this .onDoubleTap,
123
+ this .onLongPress,
114
124
this .control,
115
125
this .loop: true ,
116
126
this .curve: Curves .ease,
@@ -142,6 +152,8 @@ class Swiper extends StatefulWidget {
142
152
ValueChanged <int > onIndexChanged,
143
153
int index,
144
154
SwiperOnTap onTap,
155
+ SwiperOnDoubleTap onDoubleTap,
156
+ SwiperOnLongPress onLongPress,
145
157
bool loop: true ,
146
158
Curve curve: Curves .ease,
147
159
Axis scrollDirection: Axis .horizontal,
@@ -179,6 +191,8 @@ class Swiper extends StatefulWidget {
179
191
onIndexChanged: onIndexChanged,
180
192
index: index,
181
193
onTap: onTap,
194
+ onDoubleTap: onDoubleTap,
195
+ onLongPress: onLongPress,
182
196
curve: curve,
183
197
scrollDirection: scrollDirection,
184
198
pagination: pagination,
@@ -206,6 +220,8 @@ class Swiper extends StatefulWidget {
206
220
ValueChanged <int > onIndexChanged,
207
221
int index,
208
222
SwiperOnTap onTap,
223
+ SwiperOnDoubleTap onDoubleTap,
224
+ SwiperOnLongPress onLongPress,
209
225
bool loop: true ,
210
226
Curve curve: Curves .ease,
211
227
Axis scrollDirection: Axis .horizontal,
@@ -240,6 +256,8 @@ class Swiper extends StatefulWidget {
240
256
onIndexChanged: onIndexChanged,
241
257
index: index,
242
258
onTap: onTap,
259
+ onDoubleTap: onDoubleTap,
260
+ onLongPress: onLongPress,
243
261
curve: curve,
244
262
key: key,
245
263
scrollDirection: scrollDirection,
@@ -360,7 +378,13 @@ class _SwiperState extends _SwiperTimerMixin {
360
378
return GestureDetector (
361
379
behavior: HitTestBehavior .opaque,
362
380
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);
364
388
},
365
389
child: widget.itemBuilder (context, index),
366
390
);
@@ -397,7 +421,7 @@ class _SwiperState extends _SwiperTimerMixin {
397
421
398
422
Widget _buildSwiper () {
399
423
IndexedWidgetBuilder itemBuilder;
400
- if (widget.onTap != null ) {
424
+ if (widget.onTap != null || widget.onDoubleTap != null || widget.onLongPress != null ) {
401
425
itemBuilder = _wrapTap;
402
426
} else {
403
427
itemBuilder = widget.itemBuilder;
0 commit comments