Skip to content

Commit

Permalink
bumped to version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nixrajput committed Aug 11, 2023
1 parent 6f1a3e5 commit 160dd55
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 773 deletions.
686 changes: 17 additions & 669 deletions LICENSE

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ linter:
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_generic_function_type_aliases
- prefer_initializing_formals
Expand Down
128 changes: 66 additions & 62 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,26 @@ class ComplicatedImageDemo extends StatelessWidget {
final deviceSize = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(title: const Text('Image Slider Demo')),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.width,
),
child: FlutterCarousel(
options: CarouselOptions(
autoPlay: false,
autoPlayInterval: const Duration(seconds: 5),
disableCenter: true,
viewportFraction: 0.8,
height: deviceSize.height * 0.45,
indicatorMargin: 12.0,
enableInfiniteScroll: false,
slideIndicator: const CircularSlideIndicator(),
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.width,
),
child: FlutterCarousel(
options: CarouselOptions(
autoPlay: true,
autoPlayInterval: const Duration(seconds: 3),
disableCenter: true,
viewportFraction: 0.8,
height: deviceSize.height * 0.45,
indicatorMargin: 12.0,
enableInfiniteScroll: true,
slideIndicator: const CircularSlideIndicator(),
),
items: sliders,
),
items: sliders,
),
),
),
Expand Down Expand Up @@ -231,57 +233,59 @@ class _ManuallyControlledSliderState extends State<ManuallyControlledSlider> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Manually Controlled Slider')),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: FlutterCarousel(
items: sliders,
options: CarouselOptions(
viewportFraction: 1.0,
autoPlay: false,
floatingIndicator: false,
enableInfiniteScroll: true,
controller: _controller,
slideIndicator: CircularWaveSlideIndicator(),
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: FlutterCarousel(
items: sliders,
options: CarouselOptions(
viewportFraction: 1.0,
autoPlay: false,
floatingIndicator: false,
enableInfiniteScroll: true,
controller: _controller,
slideIndicator: CircularWaveSlideIndicator(),
),
),
),
),
const SizedBox(height: 16.0),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 16.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: ElevatedButton(
onPressed: _controller.previousPage,
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(Icons.arrow_back),
const SizedBox(height: 16.0),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 16.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: ElevatedButton(
onPressed: _controller.previousPage,
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(Icons.arrow_back),
),
),
),
),
Flexible(
child: ElevatedButton(
onPressed: _controller.nextPage,
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(Icons.arrow_forward),
Flexible(
child: ElevatedButton(
onPressed: _controller.nextPage,
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(Icons.arrow_forward),
),
),
),
),
],
),
)
],
],
),
)
],
),
),
),
);
Expand Down
90 changes: 54 additions & 36 deletions lib/src/_flutter_carousel_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class FlutterCarouselState extends State<FlutterCarousel>

@override
void didUpdateWidget(covariant FlutterCarousel oldWidget) {
super.didUpdateWidget(oldWidget);
_carouselState!.options = options;
_carouselState!.itemCount = widget.itemCount;

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

_pageController!.addListener(() {
var realIndex = getRealIndex(
_carouselState!.pageController!.page!.floor(),
_carouselState!.realPage,
widget.itemCount ?? widget.items?.length,
);
setState(() {
_currentPage = _pageController!.page!.floor();
_currentPage = realIndex;
_pageDelta = _pageController!.page! - _pageController!.page!.floor();
});
});

super.didUpdateWidget(oldWidget);
}

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

/// For Indicator
_currentPage = widget.options.initialPage;

_handleAutoPlay();

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

_pageController!.addListener(() {
var realIndex = getRealIndex(
_carouselState!.pageController!.page!.floor(),
_carouselState!.realPage,
widget.itemCount ?? widget.items?.length,
);
setState(() {
_currentPage = _pageController!.page!.floor();
_currentPage = realIndex;
_pageDelta = _pageController!.page! - _pageController!.page!.floor();
});
});
Expand All @@ -144,36 +152,39 @@ class FlutterCarouselState extends State<FlutterCarousel>

/// Timer
Timer? _getTimer() {
if (widget.options.autoPlay == true) {
return Timer.periodic(widget.options.autoPlayInterval, (_) {
final route = ModalRoute.of(context);
if (route?.isCurrent == false) {
return;
}
if (!widget.options.autoPlay) {
return null;
}

var previousReason = mode;
_changeMode(CarouselPageChangedReason.timed);
var nextPage = _carouselState!.pageController!.page!.round() + 1;
var itemCount = widget.itemCount ?? widget.items!.length;
return Timer.periodic(widget.options.autoPlayInterval, (_) {
final route = ModalRoute.of(context);
if (route?.isCurrent == false) {
return;
}

if (nextPage >= itemCount &&
widget.options.enableInfiniteScroll == false) {
if (widget.options.pauseAutoPlayInFiniteScroll) {
_clearTimer();
return;
}
nextPage = 0;
}
var previousReason = mode;
_changeMode(CarouselPageChangedReason.timed);

_carouselState!.pageController!
.animateToPage(nextPage,
duration: widget.options.autoPlayAnimationDuration,
curve: widget.options.autoPlayCurve)
.then((_) => _changeMode(previousReason));
});
}
var itemCount = widget.itemCount ?? widget.items!.length;
var nextPage = _carouselState!.pageController!.page!.round() + 1;

if (nextPage >= itemCount &&
widget.options.enableInfiniteScroll == false) {
if (widget.options.pauseAutoPlayInFiniteScroll) {
_clearTimer();
return;
}
nextPage = 0;
}

return null;
_carouselState!.pageController!
.animateToPage(
nextPage,
duration: widget.options.autoPlayAnimationDuration,
curve: widget.options.autoPlayCurve,
)
.then((_) => _changeMode(previousReason));
});
}

void _changeMode(CarouselPageChangedReason mode) {
Expand Down Expand Up @@ -308,7 +319,10 @@ class FlutterCarouselState extends State<FlutterCarousel>
ScrollConfiguration.of(context).copyWith(
scrollbars: false,
overscroll: false,
dragDevices: {PointerDeviceKind.touch, PointerDeviceKind.mouse},
dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
},
),
clipBehavior: widget.options.clipBehavior,
physics: widget.options.physics,
Expand All @@ -321,8 +335,12 @@ class FlutterCarouselState extends State<FlutterCarousel>
restorationId: widget.options.restorationId,
padEnds: widget.options.padEnds,
onPageChanged: (int index) {
var currentPage = getRealIndex(index + _carouselState!.initialPage,
_carouselState!.realPage, widget.itemCount);
var currentPage = getRealIndex(
index + _carouselState!.initialPage,
_carouselState!.realPage,
widget.itemCount,
);

if (widget.options.onPageChanged != null) {
widget.options.onPageChanged!(currentPage, mode);
}
Expand Down Expand Up @@ -412,7 +430,7 @@ class FlutterCarouselState extends State<FlutterCarousel>
/// The method to build the slide indicator
Widget _buildSlideIndicator() {
return widget.options.slideIndicator!.build(
_currentPage % widget.itemCount!,
_currentPage,
_pageDelta,
widget.itemCount!,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/helpers/flutter_carousel_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CarouselState {
/// This value can be ignored unless you know the carousel will be scrolled
/// backwards more then 10000 pages.
/// Defaults to 10000 to simulate infinite backwards scrolling.
int realPage = 100000;
int realPage = 1000000;

/// The callback to set the Reason Carousel changed
Function(CarouselPageChangedReason) changeMode;
Expand Down
9 changes: 5 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: flutter_carousel_widget
description: A customizable carousel slider widget in Flutter which supports infinite scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.
version: 2.0.4

version: 2.1.0

homepage: https://github.com/nixrajput
repository: https://github.com/nixrajput/flutter_carousel_widget
issue_tracker: https://github.com/nixrajput/flutter_carousel_widget/issues
Expand All @@ -14,6 +16,5 @@ dependencies:
sdk: flutter

dev_dependencies:
test: ^1.22.2
flutter_lints: ^2.0.1
lints: ^2.0.1
test: ^1.24.6
flutter_lints: ^2.0.2

0 comments on commit 160dd55

Please sign in to comment.