Skip to content

Commit aeced03

Browse files
committed
bumped to version 3.0.1
1 parent 97762f9 commit aeced03

18 files changed

+134
-49
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 3.0.1
4+
5+
- **Improvement**: Added comments to the classes, controllers, states, options, and enums.
6+
- **Improvement**: Formatted the code to pass static analysis.
7+
- **Documentation**: Removed demo `gif` to reduce package size.
8+
39
## 3.0.0
410

511
- **Breaking Change**: New `FlutterCarouselOptions` introduced for `FlutterCarousel`.

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# flutter_carousel_widget
22

3-
A customizable carousel slider widget for Flutter, offering features such as infinite scrolling, auto-scrolling, custom child widgets, custom animations, pre-built indicators, expandable carousel widgets, and auto-sized child support.
3+
A customizable carousel widget for Flutter, offering features such as infinite scrolling, auto-scrolling, custom child widgets, pre-built indicators, expandable child widgets, auto-sized child support, and enlarged center page.
44

55
[![pub package](https://img.shields.io/pub/v/flutter_carousel_widget.svg?label=Version&style=flat)][pub]
66
[![Stars](https://img.shields.io/github/stars/nixrajput/flutter_carousel_widget?label=Stars&style=flat)][repo]
@@ -56,7 +56,7 @@ A customizable carousel slider widget for Flutter, offering features such as inf
5656
- **Auto-sized Child Support:** Automatically adjust the size of the carousel items to fit their content.
5757
- **Enlarge Center Page:** The focused item can be enlarged.
5858

59-
## Breaking Changes for v3.0.0
59+
## Breaking Changes for the version ^3.0.0
6060

6161
In version 3.0.0 of the package, the following breaking changes have been introduced:
6262

@@ -87,8 +87,6 @@ If you have been using CarouselOptions, CarouselController, and CarouselState fo
8787

8888
## Demo
8989

90-
![Demo](https://raw.githubusercontent.com/nixrajput/flutter_carousel_widget/master/screenshots/flutter_carousel_widget_demo.gif)
91-
9290
### [Click here to experience the demo in a Web App](https://nixrajput.github.io/flutter_carousel_widget)
9391

9492
## Installation

lib/flutter_carousel_widget.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
library flutter_carousel_widget;
2+
3+
/// Export statements to expose internal files and classes
4+
/// from the [flutter_carousel_widget] package.
5+
///
6+
/// These exports allow other files or packages to access and
7+
/// use the classes, controllers, states, options, enums, and indicators.
8+
19
export 'package:flutter_carousel_widget/src/_expandable_carousel_widget.dart';
210
export 'package:flutter_carousel_widget/src/_flutter_carousel_widget.dart';
311
export 'package:flutter_carousel_widget/src/carousel_controller/expandable_carousel_controller.dart';

lib/src/carousel_controller/expandable_carousel_controller.dart

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,37 @@ import '../carousel_state/expandable_carousel_state.dart';
66
import '../enums/carousel_page_changed_reason.dart';
77
import '../utils/flutter_carousel_utils.dart';
88

9+
/// Abstract controller class to handle carousel interactions like navigation and auto-play.
910
abstract class ExpandableCarouselController {
11+
/// Factory constructor that returns an implementation of the controller.
1012
factory ExpandableCarouselController() => ExpandableCarouselControllerImpl();
1113

14+
/// Indicates if the controller is ready.
1215
bool get ready;
1316

17+
/// Future that completes when the controller is ready.
1418
Future<void> get onReady;
1519

20+
/// Navigates to the next page in the carousel.
1621
void nextPage({Duration? duration, Curve? curve});
1722

23+
/// Navigates to the previous page in the carousel.
1824
void previousPage({Duration? duration, Curve? curve});
1925

26+
/// Jumps to a specific page in the carousel without animation.
2027
void jumpToPage(int page);
2128

29+
/// Animates the carousel to a specific page.
2230
void animateToPage(int page, {Duration? duration, Curve? curve});
2331

32+
/// Starts the auto-play functionality of the carousel.
2433
void startAutoPlay();
2534

35+
/// Stops the auto-play functionality of the carousel.
2636
void stopAutoPlay();
2737
}
2838

39+
/// Implementation of the ExpandableCarouselController interface.
2940
class ExpandableCarouselControllerImpl implements ExpandableCarouselController {
3041
final Completer<void> _readyCompleter = Completer<void>();
3142
ExpandableCarouselState? _state;
@@ -34,19 +45,23 @@ class ExpandableCarouselControllerImpl implements ExpandableCarouselController {
3445
/// The animation lasts for the given duration and follows the given curve.
3546
/// The returned [Future] resolves when the animation completes.
3647
@override
37-
void animateToPage(int page,
38-
{Duration? duration = const Duration(milliseconds: 300),
39-
Curve? curve = Curves.linear}) async {
48+
void animateToPage(
49+
int page, {
50+
Duration? duration = const Duration(milliseconds: 300),
51+
Curve? curve = Curves.linear,
52+
}) async {
4053
final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
4154

4255
if (isNeedResetTimer) {
4356
_state!.onResetTimer();
4457
}
4558

59+
// Calculate the real index to animate to.
4660
final index = getRealIndex(_state!.pageController?.page!.toInt() ?? 0,
4761
_state!.realPage - _state!.initialPage, _state!.itemCount);
4862
_setModeController();
4963

64+
// Animate to the target page.
5065
await _state!.pageController!.animateToPage(
5166
(_state!.pageController?.page!.toInt() ?? 0) + page - index,
5267
duration: duration!,
@@ -67,6 +82,7 @@ class ExpandableCarouselControllerImpl implements ExpandableCarouselController {
6782

6883
_setModeController();
6984

85+
// Jump directly to the target page.
7086
return _state!.pageController?.jumpToPage(
7187
(_state!.pageController?.page!.toInt() ?? 0) + page - index);
7288
}
@@ -75,9 +91,10 @@ class ExpandableCarouselControllerImpl implements ExpandableCarouselController {
7591
/// The animation lasts for the given duration and follows the given curve.
7692
/// The returned [Future] resolves when the animation completes.
7793
@override
78-
void nextPage(
79-
{Duration? duration = const Duration(milliseconds: 300),
80-
Curve? curve = Curves.linear}) async {
94+
void nextPage({
95+
Duration? duration = const Duration(milliseconds: 300),
96+
Curve? curve = Curves.linear,
97+
}) async {
8198
final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
8299

83100
if (isNeedResetTimer) {
@@ -86,23 +103,26 @@ class ExpandableCarouselControllerImpl implements ExpandableCarouselController {
86103

87104
_setModeController();
88105

106+
// Navigate to the next page.
89107
await _state!.pageController?.nextPage(duration: duration!, curve: curve!);
90108

91109
if (isNeedResetTimer) {
92110
_state!.onResumeTimer();
93111
}
94112
}
95113

114+
/// Future that completes when the controller is ready.
96115
@override
97116
Future<void> get onReady => _readyCompleter.future;
98117

99118
/// Animates the controlled [ExpandableCarousel] to the previous page.
100119
/// The animation lasts for the given duration and follows the given curve.
101120
/// The returned [Future] resolves when the animation completes.
102121
@override
103-
void previousPage(
104-
{Duration? duration = const Duration(milliseconds: 300),
105-
Curve? curve = Curves.linear}) async {
122+
void previousPage({
123+
Duration? duration = const Duration(milliseconds: 300),
124+
Curve? curve = Curves.linear,
125+
}) async {
106126
final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
107127

108128
if (isNeedResetTimer) {
@@ -111,6 +131,7 @@ class ExpandableCarouselControllerImpl implements ExpandableCarouselController {
111131

112132
_setModeController();
113133

134+
// Navigate to the previous page.
114135
await _state!.pageController
115136
?.previousPage(duration: duration!, curve: curve!);
116137

@@ -119,6 +140,7 @@ class ExpandableCarouselControllerImpl implements ExpandableCarouselController {
119140
}
120141
}
121142

143+
/// Checks if the controller is ready to interact with the carousel.
122144
@override
123145
bool get ready => _state != null;
124146

@@ -138,13 +160,15 @@ class ExpandableCarouselControllerImpl implements ExpandableCarouselController {
138160
_state!.onResetTimer();
139161
}
140162

163+
/// Sets the current state of the carousel.
141164
set state(ExpandableCarouselState? state) {
142165
_state = state;
143166
if (!_readyCompleter.isCompleted) {
144167
_readyCompleter.complete();
145168
}
146169
}
147170

171+
/// Sets the carousel change mode to controller-based.
148172
void _setModeController() =>
149173
_state!.changeMode(CarouselPageChangedReason.controller);
150174
}

lib/src/carousel_controller/flutter_carousel_controller.dart

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@ import '../enums/carousel_page_changed_reason.dart';
77
import '../utils/flutter_carousel_utils.dart';
88

99
abstract class FlutterCarouselController {
10+
/// Factory constructor that returns an implementation of the controller.
1011
factory FlutterCarouselController() => FlutterCarouselControllerImpl();
1112

13+
/// Indicates if the controller is ready.
1214
bool get ready;
1315

16+
/// Future that completes when the controller is ready.
1417
Future<void> get onReady;
1518

19+
/// Navigates to the next page in the carousel.
1620
void nextPage({Duration? duration, Curve? curve});
1721

22+
/// Navigates to the previous page in the carousel.
1823
void previousPage({Duration? duration, Curve? curve});
1924

25+
/// Jumps to a specific page in the carousel without animation.
2026
void jumpToPage(int page);
2127

28+
/// Animates the carousel to a specific page.
2229
void animateToPage(int page, {Duration? duration, Curve? curve});
2330

31+
/// Starts the auto-play functionality of the carousel.
2432
void startAutoPlay();
2533

34+
/// Stops the auto-play functionality of the carousel.
2635
void stopAutoPlay();
2736
}
2837

@@ -34,19 +43,24 @@ class FlutterCarouselControllerImpl implements FlutterCarouselController {
3443
/// The animation lasts for the given duration and follows the given curve.
3544
/// The returned [Future] resolves when the animation completes.
3645
@override
37-
void animateToPage(int page,
38-
{Duration? duration = const Duration(milliseconds: 300),
39-
Curve? curve = Curves.linear}) async {
46+
void animateToPage(
47+
int page, {
48+
Duration? duration = const Duration(milliseconds: 300),
49+
Curve? curve = Curves.linear,
50+
}) async {
4051
final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
4152

4253
if (isNeedResetTimer) {
4354
_state!.onResetTimer();
4455
}
56+
57+
// Calculate the real index to animate to.
4558
final index = getRealIndex(_state!.pageController?.page!.toInt() ?? 0,
4659
_state!.realPage - _state!.initialPage, _state!.itemCount);
4760

4861
_setModeController();
4962

63+
// Animate to the target page.
5064
await _state!.pageController!.animateToPage(
5165
(_state!.pageController?.page!.toInt() ?? 0) + page - index,
5266
duration: duration!,
@@ -67,6 +81,7 @@ class FlutterCarouselControllerImpl implements FlutterCarouselController {
6781

6882
_setModeController();
6983

84+
// Jump directly to the target page.
7085
return _state!.pageController?.jumpToPage(
7186
(_state!.pageController?.page!.toInt() ?? 0) + page - index);
7287
}
@@ -75,9 +90,10 @@ class FlutterCarouselControllerImpl implements FlutterCarouselController {
7590
/// The animation lasts for the given duration and follows the given curve.
7691
/// The returned [Future] resolves when the animation completes.
7792
@override
78-
void nextPage(
79-
{Duration? duration = const Duration(milliseconds: 300),
80-
Curve? curve = Curves.linear}) async {
93+
void nextPage({
94+
Duration? duration = const Duration(milliseconds: 300),
95+
Curve? curve = Curves.linear,
96+
}) async {
8197
final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
8298

8399
if (isNeedResetTimer) {
@@ -86,23 +102,26 @@ class FlutterCarouselControllerImpl implements FlutterCarouselController {
86102

87103
_setModeController();
88104

105+
// Navigate to the next page.
89106
await _state!.pageController?.nextPage(duration: duration!, curve: curve!);
90107

91108
if (isNeedResetTimer) {
92109
_state!.onResumeTimer();
93110
}
94111
}
95112

113+
/// Future that completes when the controller is ready.
96114
@override
97115
Future<void> get onReady => _readyCompleter.future;
98116

99117
/// Animates the controlled [FlutterCarousel] to the previous page.
100118
/// The animation lasts for the given duration and follows the given curve.
101119
/// The returned [Future] resolves when the animation completes.
102120
@override
103-
void previousPage(
104-
{Duration? duration = const Duration(milliseconds: 300),
105-
Curve? curve = Curves.linear}) async {
121+
void previousPage({
122+
Duration? duration = const Duration(milliseconds: 300),
123+
Curve? curve = Curves.linear,
124+
}) async {
106125
final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
107126

108127
if (isNeedResetTimer) {
@@ -111,6 +130,7 @@ class FlutterCarouselControllerImpl implements FlutterCarouselController {
111130

112131
_setModeController();
113132

133+
// Navigate to the previous page.
114134
await _state!.pageController!
115135
.previousPage(duration: duration!, curve: curve!);
116136

@@ -119,6 +139,7 @@ class FlutterCarouselControllerImpl implements FlutterCarouselController {
119139
}
120140
}
121141

142+
/// Checks if the controller is ready to interact with the carousel.
122143
@override
123144
bool get ready => _state != null;
124145

@@ -138,13 +159,15 @@ class FlutterCarouselControllerImpl implements FlutterCarouselController {
138159
_state!.onResetTimer();
139160
}
140161

162+
/// Sets the current state of the carousel.
141163
set state(FlutterCarouselState? state) {
142164
_state = state;
143165
if (!_readyCompleter.isCompleted) {
144166
_readyCompleter.complete();
145167
}
146168
}
147169

170+
/// Sets the carousel change mode to controller-based.
148171
void _setModeController() =>
149172
_state!.changeMode(CarouselPageChangedReason.controller);
150173
}

lib/src/carousel_options/base_carousel_options.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import '../enums/carousel_page_changed_reason.dart';
55
import '../enums/center_page_enlarge_strategy.dart';
66
import '../indicators/slide_indicator.dart';
77

8+
/// Abstract class for carousel options, defining base configuration parameters.
9+
/// This class can be extended to create more specific carousel options for different carousel types.
810
abstract class BaseCarouselOptions {
911
BaseCarouselOptions({
1012
this.aspectRatio,

lib/src/carousel_options/expandable_carousel_options.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import '../enums/center_page_enlarge_strategy.dart';
77
import '../indicators/slide_indicator.dart';
88
import 'base_carousel_options.dart';
99

10+
/// The [ExpandableCarouselOptions] class extends [BaseCarouselOptions] and
11+
/// adds more configuration options specific to the [ExpandableCarousel] widget.
1012
class ExpandableCarouselOptions extends BaseCarouselOptions {
1113
ExpandableCarouselOptions({
1214
this.controller,
@@ -91,6 +93,8 @@ class ExpandableCarouselOptions extends BaseCarouselOptions {
9193

9294
/// Copy With Constructor
9395
ExpandableCarouselOptions copyWith({
96+
ExpandableCarouselController? controller,
97+
double? estimatedPageSize,
9498
double? aspectRatio,
9599
double? viewportFraction,
96100
int? initialPage,
@@ -101,7 +105,6 @@ class ExpandableCarouselOptions extends BaseCarouselOptions {
101105
Duration? autoPlayAnimationDuration,
102106
Curve? autoPlayCurve,
103107
Axis? scrollDirection,
104-
ExpandableCarouselController? carouselController,
105108
Function(int index, CarouselPageChangedReason reason)? onPageChanged,
106109
ValueChanged<double?>? onScrolled,
107110
ScrollPhysics? physics,
@@ -125,9 +128,9 @@ class ExpandableCarouselOptions extends BaseCarouselOptions {
125128
double? enlargeFactor,
126129
CenterPageEnlargeStrategy? enlargeStrategy,
127130
bool? disableCenter,
128-
double? estimatedPageSize,
129131
}) {
130132
return ExpandableCarouselOptions(
133+
controller: controller ?? this.controller,
131134
aspectRatio: aspectRatio ?? this.aspectRatio,
132135
viewportFraction: viewportFraction ?? this.viewportFraction,
133136
initialPage: initialPage ?? this.initialPage,

0 commit comments

Comments
 (0)