-
Notifications
You must be signed in to change notification settings - Fork 720
/
Copy pathswiper_control.dart
106 lines (92 loc) · 3.09 KB
/
swiper_control.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
class SwiperControl extends SwiperPlugin {
///IconData for previous
final IconData iconPrevious;
///iconData fopr next
final IconData iconNext;
///icon size
final double size;
///Icon normal color, The theme's [ThemeData.primaryColor] by default.
final Color color;
///if set loop=false on Swiper, this color will be used when swiper goto the last slide.
///The theme's [ThemeData.disabledColor] by default.
final Color disableColor;
final EdgeInsetsGeometry padding;
final Key key;
const SwiperControl(
{this.iconPrevious: Icons.arrow_back_ios,
this.iconNext: Icons.arrow_forward_ios,
this.color,
this.disableColor,
this.key,
this.size: 30.0,
this.padding: const EdgeInsets.all(5.0)});
Widget buildButton(SwiperPluginConfig config, Color color, IconData iconDaga,
int quarterTurns, bool previous) {
return new GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
///condition onTap animation to loop status or presence of previous or next index (avoiding jump-loop).
bool isPrev = config.activeIndex > 0;
bool isNext = config.activeIndex < config.itemCount - 1;
if (previous) {
if (isPrev || config.loop) config.controller.previous(animation: true);
} else {
if (isNext || config.loop) config.controller.next(animation: true);
}
},
child: Padding(
padding: padding,
child: RotatedBox(
quarterTurns: quarterTurns,
child: Icon(
iconDaga,
semanticLabel: previous ? "Previous" : "Next",
size: size,
color: color,
))),
);
}
@override
Widget build(BuildContext context, SwiperPluginConfig config) {
ThemeData themeData = Theme.of(context);
Color color = this.color ?? themeData.primaryColor;
Color disableColor = this.disableColor ?? themeData.disabledColor;
Color prevColor;
Color nextColor;
if (config.loop) {
prevColor = nextColor = color;
} else {
bool next = config.activeIndex < config.itemCount - 1;
bool prev = config.activeIndex > 0;
prevColor = prev ? color : disableColor;
nextColor = next ? color : disableColor;
}
Widget child;
if (config.scrollDirection == Axis.horizontal) {
child = Row(
key: key,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
buildButton(config, prevColor, iconPrevious, 0, true),
buildButton(config, nextColor, iconNext, 0, false)
],
);
} else {
child = Column(
key: key,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
buildButton(config, prevColor, iconPrevious, -3, true),
buildButton(config, nextColor, iconNext, -3, false)
],
);
}
return new Container(
height: double.infinity,
child: child,
width: double.infinity,
);
}
}