@@ -52,7 +52,7 @@ class GFCarousel extends StatefulWidget {
52
52
final num viewportFraction;
53
53
54
54
/// The initial page to show when first creating the [GFCarousel] . Defaults to 0.
55
- final num initialPage;
55
+ final int initialPage;
56
56
57
57
/// Determines if slides should loop infinitely or be limited to item length. Defaults to true, i.e. infinite loop.
58
58
final bool enableInfiniteScroll;
@@ -125,23 +125,24 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
125
125
126
126
/// The actual index of the [PageView] .
127
127
int realPage = 10000 ;
128
+ int ? currentSlide;
128
129
129
130
@override
130
131
void initState () {
131
132
super .initState ();
132
133
realPage = widget.enableInfiniteScroll
133
134
// ignore: avoid_as
134
- ? realPage + ( widget.initialPage as int )
135
+ ? realPage + widget.initialPage
135
136
// ignore: avoid_as
136
- : widget.initialPage as int ;
137
+ : widget.initialPage;
137
138
pageController = PageController (
138
139
// ignore: avoid_as
139
140
viewportFraction: widget.viewportFraction as double ,
140
141
initialPage: widget.enableInfiniteScroll
141
142
// ignore: avoid_as
142
- ? realPage + ( widget.initialPage as int )
143
+ ? realPage + widget.initialPage
143
144
// ignore: avoid_as
144
- : widget.initialPage as int ,
145
+ : widget.initialPage,
145
146
);
146
147
timer = getPlayTimer ();
147
148
}
@@ -189,8 +190,6 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
189
190
setState (() => currentSlide = index);
190
191
}
191
192
192
- int ? currentSlide;
193
-
194
193
@override
195
194
Widget build (BuildContext context) => Stack (
196
195
children: < Widget > [
@@ -206,25 +205,23 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
206
205
: widget.items.length,
207
206
onPageChanged: (int index) {
208
207
int currentPage;
209
- // ignore: avoid_as
210
- currentPage = _getRealIndex (index + (widget.initialPage as int ),
211
- realPage, widget.items.length);
208
+ currentPage = _getRealIndex (
209
+ index + widget.initialPage, realPage, widget.items.length);
212
210
if (widget.onPageChanged != null ) {
213
211
widget.onPageChanged !(currentPage);
214
212
}
215
- if (widget.pagination == true && widget.onPageChanged == null ) {
213
+ if (widget.pagination == true ) {
216
214
onPageSlide (currentPage);
217
215
}
218
216
},
219
217
itemBuilder: (BuildContext context, int i) {
220
- final int index = _getRealIndex (
221
- // ignore: avoid_as
222
- i + ( widget.initialPage as int ) ,
218
+ int index;
219
+ index = _getRealIndex (
220
+ i + widget.initialPage,
223
221
realPage,
224
222
widget.items.length,
225
223
);
226
-
227
- currentSlide = index;
224
+ currentSlide = widget.initialPage;
228
225
return AnimatedBuilder (
229
226
animation: pageController,
230
227
child: widget.items[index],
@@ -283,27 +280,29 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
283
280
child: Row (
284
281
mainAxisAlignment: MainAxisAlignment .center,
285
282
children: widget.map <Widget >(
286
- widget.items,
287
- (pagerIndex, url) => Container (
288
- width:
289
- widget.pagerSize == null ? 8.0 : widget.pagerSize,
290
- height:
291
- widget.pagerSize == null ? 8.0 : widget.pagerSize,
292
- margin: const EdgeInsets .symmetric (
293
- vertical: 10 , horizontal: 2 ),
294
- decoration: BoxDecoration (
295
- shape: BoxShape .circle,
296
- color: currentSlide == pagerIndex
297
- ? widget.activeIndicator == null
298
- ? const Color .fromRGBO (0 , 0 , 0 , 0.9 )
299
- : widget.activeIndicator!
300
- : widget.passiveIndicator == null
301
- ? const Color .fromRGBO (0 , 0 , 0 , 0.4 )
302
- : widget.passiveIndicator! ,
283
+ widget.items,
284
+ (pagerIndex, url) => Container (
285
+ width: widget.pagerSize == null
286
+ ? 8.0
287
+ : widget.pagerSize,
288
+ height: widget.pagerSize == null
289
+ ? 8.0
290
+ : widget.pagerSize,
291
+ margin: const EdgeInsets .symmetric (
292
+ vertical: 10 , horizontal: 2 ),
293
+ decoration: BoxDecoration (
294
+ shape: BoxShape .circle,
295
+ color: currentSlide == pagerIndex
296
+ ? widget.activeIndicator == null
297
+ ? const Color .fromRGBO (0 , 0 , 0 , 0.9 )
298
+ : widget.activeIndicator!
299
+ : widget.passiveIndicator == null
300
+ ? const Color .fromRGBO (0 , 0 , 0 , 0.4 )
301
+ : widget.passiveIndicator! ,
302
+ ),
303
+ )
304
+ // ignore: avoid_as
303
305
),
304
- ),
305
- // ignore: avoid_as
306
- ),
307
306
),
308
307
),
309
308
)
0 commit comments