From 7992d71076ecfe79330e9646d0766b41f38058bf Mon Sep 17 00:00:00 2001 From: Niels Gorter Date: Tue, 26 Sep 2023 09:53:56 +0200 Subject: [PATCH 1/3] fix: https://github.com/Iconica-Development/flutter_carousel/issues/5 --- lib/src/carousel.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/src/carousel.dart b/lib/src/carousel.dart index 6337b17..cd08f97 100644 --- a/lib/src/carousel.dart +++ b/lib/src/carousel.dart @@ -21,6 +21,8 @@ class Carousel extends StatefulWidget { this.onPageChanged, this.alignment = AlignmentDirectional.topStart, this.onCardClick, + this.initialPage = 0, + this.allowInfiniteScrollingBackwards = false, Key? key, }) : super(key: key); @@ -46,16 +48,29 @@ class Carousel extends StatefulWidget { /// Size of the pageview used to capture swipe gestures. final double pageViewHeight; + /// The page to show when first creating the [Carousel]. + final int initialPage; + + /// Whether to allow infinite scrolling backwards. Defaults to false. If true, this works by using a very large number of pages (10000). Works in conjunction with [initialPage]. + final bool allowInfiniteScrollingBackwards; + @override State createState() => _CarouselState(); } class _CarouselState extends State { - final PageController _pageController = PageController(initialPage: 0); + late PageController _pageController; double _currentPage = 0; @override void initState() { + _pageController = PageController( + initialPage: widget.allowInfiniteScrollingBackwards + ? 10000 + widget.initialPage + : widget.initialPage, + ); + _currentPage = _pageController.initialPage.toDouble(); + _pageController.addListener(() { _currentPage = _pageController.page!; }); From 782361b846cb0672745af55bdc6bb09ec2b2a5dc Mon Sep 17 00:00:00 2001 From: Niels Gorter Date: Tue, 26 Sep 2023 09:57:59 +0200 Subject: [PATCH 2/3] fix linter --- example/lib/pokemon_types.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/pokemon_types.dart b/example/lib/pokemon_types.dart index 1504291..5b108f5 100644 --- a/example/lib/pokemon_types.dart +++ b/example/lib/pokemon_types.dart @@ -17,4 +17,4 @@ enum PokemonType { dragon, steel, fairy, -} \ No newline at end of file +} From 19d008c41110e973c35ec5ef9d9edd42acd50f4d Mon Sep 17 00:00:00 2001 From: Niels Gorter Date: Tue, 26 Sep 2023 10:12:08 +0200 Subject: [PATCH 3/3] fix linter --- .github/workflows/flutter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index 50bb90a..328d54a 100644 --- a/.github/workflows/flutter.yml +++ b/.github/workflows/flutter.yml @@ -27,6 +27,6 @@ jobs: - name: Flutter pub get run: flutter pub get - name: Flutter format - run: flutter format -o none --set-exit-if-changed . + run: dart format -o none --set-exit-if-changed . - name: Flutter analyze run: flutter analyze