Skip to content

Commit 7d8ff20

Browse files
committed
GFSlider component animation completed
1 parent ba425ba commit 7d8ff20

2 files changed

Lines changed: 31 additions & 62 deletions

File tree

example/lib/main.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class _CarouselWithIndicatorState extends State<CarouselWithIndicator> {
7575
GFSlider(
7676
items: child,
7777
autoPlay: true,
78-
enlargeCenterPage: true,
78+
enlargeMainPage: true,
7979
aspectRatio: 2.0,
8080
onPageChanged: (index) {
8181
setState(() {
@@ -112,17 +112,17 @@ class CarouselDemo extends StatelessWidget {
112112
final GFSlider manualCarouselDemo = GFSlider(
113113
items: child,
114114
autoPlay: false,
115-
enlargeCenterPage: true,
115+
enlargeMainPage: true,
116116
viewportFraction: 0.9,
117117
aspectRatio: 2.0,
118118
);
119119

120120
//Auto playing carousel
121121
final GFSlider autoPlayDemo = GFSlider(
122-
viewportFraction: 0.9,
122+
viewportFraction: 0.95,
123123
aspectRatio: 2.0,
124124
autoPlay: true,
125-
enlargeCenterPage: true,
125+
enlargeMainPage: true,
126126
items: imgList.map(
127127
(url) {
128128
return Container(
@@ -145,7 +145,7 @@ class CarouselDemo extends StatelessWidget {
145145
final basicSlider = GFSlider(
146146
items: child,
147147
autoPlay: false,
148-
enlargeCenterPage: true,
148+
enlargeMainPage: true,
149149
viewportFraction: 0.9,
150150
aspectRatio: 2.0,
151151
);
@@ -181,7 +181,7 @@ class CarouselDemo extends StatelessWidget {
181181
viewportFraction: 1.0,
182182
aspectRatio: 2.0,
183183
autoPlay: false,
184-
enlargeCenterPage: false,
184+
enlargeMainPage: false,
185185
items: map<Widget>(
186186
imgList,
187187
(index, i) {
@@ -199,7 +199,7 @@ class CarouselDemo extends StatelessWidget {
199199
viewportFraction: 0.9,
200200
aspectRatio: 2.0,
201201
autoPlay: true,
202-
enlargeCenterPage: true,
202+
enlargeMainPage: true,
203203
pauseAutoPlayOnTouch: Duration(seconds: 3),
204204
items: imgList.map(
205205
(url) {
@@ -224,7 +224,7 @@ class CarouselDemo extends StatelessWidget {
224224
scrollPhysics: BouncingScrollPhysics(),
225225
enableInfiniteScroll: false,
226226
autoPlay: false,
227-
enlargeCenterPage: true,
227+
enlargeMainPage: true,
228228
viewportFraction: 0.9,
229229
aspectRatio: 2.0,
230230
);
@@ -234,7 +234,7 @@ class CarouselDemo extends StatelessWidget {
234234
scrollDirection: Axis.vertical,
235235
aspectRatio: 2.0,
236236
autoPlay: true,
237-
enlargeCenterPage: true,
237+
enlargeMainPage: true,
238238
viewportFraction: 0.9,
239239
pauseAutoPlayOnTouch: Duration(seconds: 3),
240240
items: imgList.map(

lib/components/slider/gf_slider.dart

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GFSlider extends StatefulWidget {
1616
this.autoPlayAnimationDuration = const Duration(milliseconds: 800),
1717
this.autoPlayCurve: Curves.fastOutSlowIn,
1818
this.pauseAutoPlayOnTouch,
19-
this.enlargeCenterPage = false,
19+
this.enlargeMainPage = false,
2020
this.onPageChanged,
2121
this.scrollPhysics,
2222
this.scrollDirection: Axis.horizontal})
@@ -26,81 +26,50 @@ class GFSlider extends StatefulWidget {
2626
initialPage: enableInfiniteScroll ? realPage + initialPage : initialPage,
2727
);
2828

29-
/// The widgets to be shown in the carousel.
29+
/// The widgets to be shown as sliders.
3030
final List<Widget> items;
3131

32-
/// Set carousel height and overrides any existing [aspectRatio].
32+
/// Set slide widget height and overrides any existing [aspectRatio].
3333
final double height;
3434

35-
/// Aspect ratio is used if no height have been declared.
36-
///
37-
/// Defaults to 16:9 aspect ratio.
35+
/// Aspect ratio is used if no height have been declared. Defaults to 16:9 aspect ratio.
3836
final double aspectRatio;
3937

40-
/// The fraction of the viewport that each page should occupy.
41-
///
42-
/// Defaults to 0.8, which means each page fills 80% of the carousel.
38+
/// The fraction of the viewport that each page should occupy. Defaults to 0.8, which means each page fills 80% of the slide.
4339
final num viewportFraction;
4440

45-
/// The initial page to show when first creating the [GFSlider].
46-
///
47-
/// Defaults to 0.
41+
/// The initial page to show when first creating the [GFSlider]. Defaults to 0.
4842
final num initialPage;
4943

5044
/// The actual index of the [PageView].
51-
///
52-
/// This value can be ignored unless you know the carousel will be scrolled
53-
/// backwards more then 10000 pages.
54-
/// Defaults to 10000 to simulate infinite backwards scrolling.
5545
final num realPage;
5646

57-
///Determines if carousel should loop infinitely or be limited to item length.
58-
///
59-
///Defaults to true, i.e. infinite loop.
47+
/// Determines if slides should loop infinitely or be limited to item length. Defaults to true, i.e. infinite loop.
6048
final bool enableInfiniteScroll;
6149

62-
/// Reverse the order of items if set to true.
63-
///
64-
/// Defaults to false.
50+
/// Reverse the order of items if set to true. Defaults to false.
6551
final bool reverse;
6652

67-
/// Enables auto play, sliding one page at a time.
68-
///
69-
/// Use [autoPlayInterval] to determent the frequency of slides.
70-
/// Defaults to false.
53+
/// Enables auto play, sliding one page at a time. Use [autoPlayInterval] to determent the frequency of slides. Defaults to false.
7154
final bool autoPlay;
7255

73-
/// Sets Duration to determent the frequency of slides when
74-
///
75-
/// [autoPlay] is set to true.
76-
/// Defaults to 4 seconds.
56+
/// Sets Duration to determent the frequency of slides when [autoPlay] is set to true. Defaults to 4 seconds.
7757
final Duration autoPlayInterval;
7858

79-
/// The animation duration between two transitioning pages while in auto playback.
80-
///
81-
/// Defaults to 800 ms.
59+
/// The animation duration between two transitioning pages while in auto playback. Defaults to 800 ms.
8260
final Duration autoPlayAnimationDuration;
8361

84-
/// Determines the animation curve physics.
85-
///
86-
/// Defaults to [Curves.fastOutSlowIn].
62+
/// Determines the animation curve physics. Defaults to [Curves.fastOutSlowIn].
8763
final Curve autoPlayCurve;
8864

89-
/// Sets a timer on touch detected that pause the auto play with
90-
/// the given [Duration].
91-
///
92-
/// Touch Detection is only active if [autoPlay] is true.
65+
/// Sets a timer on touch detected that pause the auto play with the given [Duration]. Touch Detection is only active if [autoPlay] is true.
9366
final Duration pauseAutoPlayOnTouch;
9467

9568
/// Determines if current page should be larger then the side images,
96-
/// creating a feeling of depth in the carousel.
97-
///
98-
/// Defaults to false.
99-
final bool enlargeCenterPage;
69+
/// creating a feeling of depth in the carousel. Defaults to false.
70+
final bool enlargeMainPage;
10071

101-
/// The axis along which the page view scrolls.
102-
///
103-
/// Defaults to [Axis.horizontal].
72+
/// The axis along which the page view scrolls. Defaults to [Axis.horizontal].
10473
final Axis scrollDirection;
10574

10675
/// Called whenever the page in the center of the viewport changes.
@@ -166,10 +135,10 @@ class _GFSliderState extends State<GFSlider> with TickerProviderStateMixin {
166135
@override
167136
void initState() {
168137
super.initState();
169-
timer = getTimer();
138+
timer = getPlayTimer();
170139
}
171140

172-
Timer getTimer() {
141+
Timer getPlayTimer() {
173142
return Timer.periodic(widget.autoPlayInterval, (_) {
174143
if (widget.autoPlay) {
175144
widget.pageController
@@ -181,11 +150,11 @@ class _GFSliderState extends State<GFSlider> with TickerProviderStateMixin {
181150
void pauseOnTouch() {
182151
timer.cancel();
183152
timer = Timer(widget.pauseAutoPlayOnTouch, () {
184-
timer = getTimer();
153+
timer = getPlayTimer();
185154
});
186155
}
187156

188-
Widget getWrapper(Widget child) {
157+
Widget getPageWrapper(Widget child) {
189158
if (widget.height != null) {
190159
final Widget wrapper = Container(height: widget.height, child: child);
191160
return widget.autoPlay && widget.pauseAutoPlayOnTouch != null
@@ -210,7 +179,7 @@ class _GFSliderState extends State<GFSlider> with TickerProviderStateMixin {
210179

211180
@override
212181
Widget build(BuildContext context) {
213-
return getWrapper(PageView.builder(
182+
return getPageWrapper(PageView.builder(
214183
physics: widget.scrollPhysics,
215184
scrollDirection: widget.scrollDirection,
216185
controller: widget.pageController,
@@ -245,7 +214,7 @@ class _GFSliderState extends State<GFSlider> with TickerProviderStateMixin {
245214
final double height =
246215
widget.height ?? MediaQuery.of(context).size.width * (1 / widget.aspectRatio);
247216
final double distortionValue =
248-
widget.enlargeCenterPage ? Curves.easeOut.transform(value) : 1.0;
217+
widget.enlargeMainPage ? Curves.easeOut.transform(value) : 1.0;
249218

250219
if (widget.scrollDirection == Axis.horizontal) {
251220
return Center(child: SizedBox(height: distortionValue * height, child: child));

0 commit comments

Comments
 (0)