diff --git a/example/lib/main.dart b/example/lib/main.dart index 149fe89..ae9b0cf 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -540,6 +540,8 @@ class _ExpandableCarouselDemoState extends State { ExpandableCarousel( options: ExpandableCarouselOptions( // viewportFraction: 1.0, + enableInfiniteScroll: false, + // initialPage: 3, autoPlay: true, controller: _controller, floatingIndicator: false, diff --git a/lib/src/_expandable_carousel_widget.dart b/lib/src/_expandable_carousel_widget.dart index 01a4950..5580289 100644 --- a/lib/src/_expandable_carousel_widget.dart +++ b/lib/src/_expandable_carousel_widget.dart @@ -6,9 +6,9 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_carousel_widget/src/components/overflow_page.dart'; import 'package:flutter_carousel_widget/src/enums/carousel_page_changed_reason.dart'; -import 'package:flutter_carousel_widget/src/helpers/flutter_carousel_controller.dart'; -import 'package:flutter_carousel_widget/src/helpers/flutter_carousel_options.dart'; -import 'package:flutter_carousel_widget/src/helpers/flutter_carousel_state.dart'; +import 'package:flutter_carousel_widget/src/helpers/flutter_expandable_carousel_controller.dart'; +import 'package:flutter_carousel_widget/src/helpers/flutter_expandable_carousel_options.dart'; +import 'package:flutter_carousel_widget/src/helpers/flutter_expandable_carousel_state.dart'; import 'package:flutter_carousel_widget/src/typedefs/widget_builder.dart'; import 'package:flutter_carousel_widget/src/utils/flutter_carousel_utils.dart'; @@ -52,18 +52,19 @@ class ExpandableCarousel extends StatefulWidget { final List? items; /// [ExpandableCarouselOptions] to create a [ExpandableCarouselState] with - final CarouselOptions options; + final ExpandableCarouselOptions options; @override - ExpandableCarouselState createState() => ExpandableCarouselState(); + ExpandableCarouselWidgetState createState() => + ExpandableCarouselWidgetState(); } -class ExpandableCarouselState extends State +class ExpandableCarouselWidgetState extends State with TickerProviderStateMixin { /// mode is related to why the page is being changed CarouselPageChangedReason mode = CarouselPageChangedReason.controller; - CarouselState? _carouselState; + ExpandableCarouselState? _carouselState; int _currentPage = 0; bool _firstPageLoaded = false; PageController? _pageController; @@ -73,7 +74,7 @@ class ExpandableCarouselState extends State late List _sizes; Timer? _timer; - CarouselOptions get options => widget.options; + ExpandableCarouselOptions get options => widget.options; bool get isBuilder => widget.itemBuilder != null; @@ -155,7 +156,7 @@ class ExpandableCarouselState extends State void initState() { super.initState(); - _carouselState = CarouselState( + _carouselState = ExpandableCarouselState( options, _clearTimer, _resumeTimer, @@ -202,10 +203,10 @@ class ExpandableCarouselState extends State super.dispose(); } - CarouselControllerImpl get carouselController => + ExpandableCarouselControllerImpl get carouselController => widget.options.controller != null - ? widget.options.controller as CarouselControllerImpl - : CarouselController() as CarouselControllerImpl; + ? widget.options.controller as ExpandableCarouselControllerImpl + : ExpandableCarouselController() as ExpandableCarouselControllerImpl; /// Timer Timer? _getTimer() { @@ -218,6 +219,7 @@ class ExpandableCarouselState extends State var previousReason = mode; _changeMode(CarouselPageChangedReason.timed); + var nextPage = _carouselState!.pageController!.page!.round() + 1; var itemCount = widget.itemCount ?? widget.items!.length; diff --git a/lib/src/_flutter_carousel_widget.dart b/lib/src/_flutter_carousel_widget.dart index 61d530b..b2025f2 100644 --- a/lib/src/_flutter_carousel_widget.dart +++ b/lib/src/_flutter_carousel_widget.dart @@ -165,8 +165,8 @@ class FlutterCarouselState extends State var previousReason = changeReasonMode; changeMode(CarouselPageChangedReason.timed); - var itemCount = widget.itemCount ?? widget.items!.length; var nextPage = _carouselState!.pageController!.page!.round() + 1; + var itemCount = widget.itemCount ?? widget.items!.length; if (nextPage >= itemCount && widget.options.enableInfiniteScroll == false) { @@ -432,10 +432,8 @@ class FlutterCarouselState extends State /// The method to build the slide indicator Widget _buildSlideIndicator() { - final _newCurrentPage = - (widget.options.initialPage + _currentPage) % widget.itemCount!; return widget.options.slideIndicator!.build( - _newCurrentPage, + (widget.options.initialPage + _currentPage) % widget.itemCount!, _pageDelta, widget.itemCount!, );