Skip to content

Commit 160dd55

Browse files
committed
bumped to version 2.1.0
1 parent 6f1a3e5 commit 160dd55

File tree

6 files changed

+143
-773
lines changed

6 files changed

+143
-773
lines changed

LICENSE

Lines changed: 17 additions & 669 deletions
Large diffs are not rendered by default.

analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ linter:
5858
- prefer_conditional_assignment
5959
- prefer_const_constructors
6060
- prefer_contains
61-
- prefer_equal_for_default_values
6261
- prefer_final_fields
6362
- prefer_generic_function_type_aliases
6463
- prefer_initializing_formals

example/lib/main.dart

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,26 @@ class ComplicatedImageDemo extends StatelessWidget {
166166
final deviceSize = MediaQuery.of(context).size;
167167
return Scaffold(
168168
appBar: AppBar(title: const Text('Image Slider Demo')),
169-
body: Padding(
170-
padding: const EdgeInsets.all(8.0),
171-
child: Container(
172-
constraints: BoxConstraints(
173-
maxHeight: MediaQuery.of(context).size.width,
174-
),
175-
child: FlutterCarousel(
176-
options: CarouselOptions(
177-
autoPlay: false,
178-
autoPlayInterval: const Duration(seconds: 5),
179-
disableCenter: true,
180-
viewportFraction: 0.8,
181-
height: deviceSize.height * 0.45,
182-
indicatorMargin: 12.0,
183-
enableInfiniteScroll: false,
184-
slideIndicator: const CircularSlideIndicator(),
169+
body: Center(
170+
child: Padding(
171+
padding: const EdgeInsets.all(8.0),
172+
child: Container(
173+
constraints: BoxConstraints(
174+
maxHeight: MediaQuery.of(context).size.width,
175+
),
176+
child: FlutterCarousel(
177+
options: CarouselOptions(
178+
autoPlay: true,
179+
autoPlayInterval: const Duration(seconds: 3),
180+
disableCenter: true,
181+
viewportFraction: 0.8,
182+
height: deviceSize.height * 0.45,
183+
indicatorMargin: 12.0,
184+
enableInfiniteScroll: true,
185+
slideIndicator: const CircularSlideIndicator(),
186+
),
187+
items: sliders,
185188
),
186-
items: sliders,
187189
),
188190
),
189191
),
@@ -231,57 +233,59 @@ class _ManuallyControlledSliderState extends State<ManuallyControlledSlider> {
231233
Widget build(BuildContext context) {
232234
return Scaffold(
233235
appBar: AppBar(title: const Text('Manually Controlled Slider')),
234-
body: Padding(
235-
padding: const EdgeInsets.all(8.0),
236-
child: Column(
237-
mainAxisAlignment: MainAxisAlignment.start,
238-
crossAxisAlignment: CrossAxisAlignment.start,
239-
mainAxisSize: MainAxisSize.min,
240-
children: [
241-
Expanded(
242-
child: FlutterCarousel(
243-
items: sliders,
244-
options: CarouselOptions(
245-
viewportFraction: 1.0,
246-
autoPlay: false,
247-
floatingIndicator: false,
248-
enableInfiniteScroll: true,
249-
controller: _controller,
250-
slideIndicator: CircularWaveSlideIndicator(),
236+
body: Center(
237+
child: Padding(
238+
padding: const EdgeInsets.all(8.0),
239+
child: Column(
240+
mainAxisAlignment: MainAxisAlignment.start,
241+
crossAxisAlignment: CrossAxisAlignment.center,
242+
mainAxisSize: MainAxisSize.min,
243+
children: [
244+
Expanded(
245+
child: FlutterCarousel(
246+
items: sliders,
247+
options: CarouselOptions(
248+
viewportFraction: 1.0,
249+
autoPlay: false,
250+
floatingIndicator: false,
251+
enableInfiniteScroll: true,
252+
controller: _controller,
253+
slideIndicator: CircularWaveSlideIndicator(),
254+
),
251255
),
252256
),
253-
),
254-
const SizedBox(height: 16.0),
255-
Padding(
256-
padding: const EdgeInsets.symmetric(
257-
horizontal: 16.0,
258-
vertical: 16.0,
259-
),
260-
child: Row(
261-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
262-
children: [
263-
Flexible(
264-
child: ElevatedButton(
265-
onPressed: _controller.previousPage,
266-
child: const Padding(
267-
padding: EdgeInsets.all(8.0),
268-
child: Icon(Icons.arrow_back),
257+
const SizedBox(height: 16.0),
258+
Padding(
259+
padding: const EdgeInsets.symmetric(
260+
horizontal: 16.0,
261+
vertical: 16.0,
262+
),
263+
child: Row(
264+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
265+
children: [
266+
Flexible(
267+
child: ElevatedButton(
268+
onPressed: _controller.previousPage,
269+
child: const Padding(
270+
padding: EdgeInsets.all(8.0),
271+
child: Icon(Icons.arrow_back),
272+
),
269273
),
270274
),
271-
),
272-
Flexible(
273-
child: ElevatedButton(
274-
onPressed: _controller.nextPage,
275-
child: const Padding(
276-
padding: EdgeInsets.all(8.0),
277-
child: Icon(Icons.arrow_forward),
275+
Flexible(
276+
child: ElevatedButton(
277+
onPressed: _controller.nextPage,
278+
child: const Padding(
279+
padding: EdgeInsets.all(8.0),
280+
child: Icon(Icons.arrow_forward),
281+
),
278282
),
279283
),
280-
),
281-
],
282-
),
283-
)
284-
],
284+
],
285+
),
286+
)
287+
],
288+
),
285289
),
286290
),
287291
);

lib/src/_flutter_carousel_widget.dart

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class FlutterCarouselState extends State<FlutterCarousel>
6565

6666
@override
6767
void didUpdateWidget(covariant FlutterCarousel oldWidget) {
68-
super.didUpdateWidget(oldWidget);
6968
_carouselState!.options = options;
7069
_carouselState!.itemCount = widget.itemCount;
7170

@@ -83,11 +82,18 @@ class FlutterCarouselState extends State<FlutterCarousel>
8382
_handleAutoPlay();
8483

8584
_pageController!.addListener(() {
85+
var realIndex = getRealIndex(
86+
_carouselState!.pageController!.page!.floor(),
87+
_carouselState!.realPage,
88+
widget.itemCount ?? widget.items?.length,
89+
);
8690
setState(() {
87-
_currentPage = _pageController!.page!.floor();
91+
_currentPage = realIndex;
8892
_pageDelta = _pageController!.page! - _pageController!.page!.floor();
8993
});
9094
});
95+
96+
super.didUpdateWidget(oldWidget);
9197
}
9298

9399
@override
@@ -114,9 +120,6 @@ class FlutterCarouselState extends State<FlutterCarousel>
114120
? _carouselState!.realPage + _carouselState!.initialPage
115121
: _carouselState!.initialPage;
116122

117-
/// For Indicator
118-
_currentPage = widget.options.initialPage;
119-
120123
_handleAutoPlay();
121124

122125
_pageController = PageController(
@@ -128,8 +131,13 @@ class FlutterCarouselState extends State<FlutterCarousel>
128131
_carouselState!.pageController = _pageController;
129132

130133
_pageController!.addListener(() {
134+
var realIndex = getRealIndex(
135+
_carouselState!.pageController!.page!.floor(),
136+
_carouselState!.realPage,
137+
widget.itemCount ?? widget.items?.length,
138+
);
131139
setState(() {
132-
_currentPage = _pageController!.page!.floor();
140+
_currentPage = realIndex;
133141
_pageDelta = _pageController!.page! - _pageController!.page!.floor();
134142
});
135143
});
@@ -144,36 +152,39 @@ class FlutterCarouselState extends State<FlutterCarousel>
144152

145153
/// Timer
146154
Timer? _getTimer() {
147-
if (widget.options.autoPlay == true) {
148-
return Timer.periodic(widget.options.autoPlayInterval, (_) {
149-
final route = ModalRoute.of(context);
150-
if (route?.isCurrent == false) {
151-
return;
152-
}
155+
if (!widget.options.autoPlay) {
156+
return null;
157+
}
153158

154-
var previousReason = mode;
155-
_changeMode(CarouselPageChangedReason.timed);
156-
var nextPage = _carouselState!.pageController!.page!.round() + 1;
157-
var itemCount = widget.itemCount ?? widget.items!.length;
159+
return Timer.periodic(widget.options.autoPlayInterval, (_) {
160+
final route = ModalRoute.of(context);
161+
if (route?.isCurrent == false) {
162+
return;
163+
}
158164

159-
if (nextPage >= itemCount &&
160-
widget.options.enableInfiniteScroll == false) {
161-
if (widget.options.pauseAutoPlayInFiniteScroll) {
162-
_clearTimer();
163-
return;
164-
}
165-
nextPage = 0;
166-
}
165+
var previousReason = mode;
166+
_changeMode(CarouselPageChangedReason.timed);
167167

168-
_carouselState!.pageController!
169-
.animateToPage(nextPage,
170-
duration: widget.options.autoPlayAnimationDuration,
171-
curve: widget.options.autoPlayCurve)
172-
.then((_) => _changeMode(previousReason));
173-
});
174-
}
168+
var itemCount = widget.itemCount ?? widget.items!.length;
169+
var nextPage = _carouselState!.pageController!.page!.round() + 1;
170+
171+
if (nextPage >= itemCount &&
172+
widget.options.enableInfiniteScroll == false) {
173+
if (widget.options.pauseAutoPlayInFiniteScroll) {
174+
_clearTimer();
175+
return;
176+
}
177+
nextPage = 0;
178+
}
175179

176-
return null;
180+
_carouselState!.pageController!
181+
.animateToPage(
182+
nextPage,
183+
duration: widget.options.autoPlayAnimationDuration,
184+
curve: widget.options.autoPlayCurve,
185+
)
186+
.then((_) => _changeMode(previousReason));
187+
});
177188
}
178189

179190
void _changeMode(CarouselPageChangedReason mode) {
@@ -308,7 +319,10 @@ class FlutterCarouselState extends State<FlutterCarousel>
308319
ScrollConfiguration.of(context).copyWith(
309320
scrollbars: false,
310321
overscroll: false,
311-
dragDevices: {PointerDeviceKind.touch, PointerDeviceKind.mouse},
322+
dragDevices: {
323+
PointerDeviceKind.touch,
324+
PointerDeviceKind.mouse,
325+
},
312326
),
313327
clipBehavior: widget.options.clipBehavior,
314328
physics: widget.options.physics,
@@ -321,8 +335,12 @@ class FlutterCarouselState extends State<FlutterCarousel>
321335
restorationId: widget.options.restorationId,
322336
padEnds: widget.options.padEnds,
323337
onPageChanged: (int index) {
324-
var currentPage = getRealIndex(index + _carouselState!.initialPage,
325-
_carouselState!.realPage, widget.itemCount);
338+
var currentPage = getRealIndex(
339+
index + _carouselState!.initialPage,
340+
_carouselState!.realPage,
341+
widget.itemCount,
342+
);
343+
326344
if (widget.options.onPageChanged != null) {
327345
widget.options.onPageChanged!(currentPage, mode);
328346
}
@@ -412,7 +430,7 @@ class FlutterCarouselState extends State<FlutterCarousel>
412430
/// The method to build the slide indicator
413431
Widget _buildSlideIndicator() {
414432
return widget.options.slideIndicator!.build(
415-
_currentPage % widget.itemCount!,
433+
_currentPage,
416434
_pageDelta,
417435
widget.itemCount!,
418436
);

lib/src/helpers/flutter_carousel_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CarouselState {
3939
/// This value can be ignored unless you know the carousel will be scrolled
4040
/// backwards more then 10000 pages.
4141
/// Defaults to 10000 to simulate infinite backwards scrolling.
42-
int realPage = 100000;
42+
int realPage = 1000000;
4343

4444
/// The callback to set the Reason Carousel changed
4545
Function(CarouselPageChangedReason) changeMode;

pubspec.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: flutter_carousel_widget
22
description: A customizable carousel slider widget in Flutter which supports infinite scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.
3-
version: 2.0.4
3+
4+
version: 2.1.0
5+
46
homepage: https://github.com/nixrajput
57
repository: https://github.com/nixrajput/flutter_carousel_widget
68
issue_tracker: https://github.com/nixrajput/flutter_carousel_widget/issues
@@ -14,6 +16,5 @@ dependencies:
1416
sdk: flutter
1517

1618
dev_dependencies:
17-
test: ^1.22.2
18-
flutter_lints: ^2.0.1
19-
lints: ^2.0.1
19+
test: ^1.24.6
20+
flutter_lints: ^2.0.2

0 commit comments

Comments
 (0)