mirror of
https://github.com/Iconica-Development/flutter_carousel.git
synced 2025-05-19 04:13:43 +02:00
This commit is contained in:
parent
6a55bc823b
commit
7992d71076
1 changed files with 16 additions and 1 deletions
|
@ -21,6 +21,8 @@ class Carousel extends StatefulWidget {
|
||||||
this.onPageChanged,
|
this.onPageChanged,
|
||||||
this.alignment = AlignmentDirectional.topStart,
|
this.alignment = AlignmentDirectional.topStart,
|
||||||
this.onCardClick,
|
this.onCardClick,
|
||||||
|
this.initialPage = 0,
|
||||||
|
this.allowInfiniteScrollingBackwards = false,
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@ -46,16 +48,29 @@ class Carousel extends StatefulWidget {
|
||||||
/// Size of the pageview used to capture swipe gestures.
|
/// Size of the pageview used to capture swipe gestures.
|
||||||
final double pageViewHeight;
|
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
|
@override
|
||||||
State<Carousel> createState() => _CarouselState();
|
State<Carousel> createState() => _CarouselState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CarouselState extends State<Carousel> {
|
class _CarouselState extends State<Carousel> {
|
||||||
final PageController _pageController = PageController(initialPage: 0);
|
late PageController _pageController;
|
||||||
double _currentPage = 0;
|
double _currentPage = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
_pageController = PageController(
|
||||||
|
initialPage: widget.allowInfiniteScrollingBackwards
|
||||||
|
? 10000 + widget.initialPage
|
||||||
|
: widget.initialPage,
|
||||||
|
);
|
||||||
|
_currentPage = _pageController.initialPage.toDouble();
|
||||||
|
|
||||||
_pageController.addListener(() {
|
_pageController.addListener(() {
|
||||||
_currentPage = _pageController.page!;
|
_currentPage = _pageController.page!;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue