Milad-Akarie / smooth_page_indicator

Flutter Smooth PageView indicators
MIT License
1.24k stars 147 forks source link

SmoothPageIndicator work with CarouselSlider #59

Closed peterbullmatti closed 1 year ago

peterbullmatti commented 2 years ago

before SmoothPageIndicator works fine with CarouselSlider since it just needs an activeIndex, but the current version of SmoothPageIndicator need a Pagecontroller, and what I have is a CarouselController, how could I transfer this CarouselController to a pagecontroller?

SmoothPageIndicator(
              controller: _pageController // here I only have a CarouselController
              count: controller.photoFrameList.length + 1,
              effect: WormEffect(
                activeDotColor: AppColors.sadColor,
                dotColor: AppColors.sadColor.withOpacity(0.4),
                dotHeight: 8,
                dotWidth: 8,
                type: WormType.thin,
                // strokeWidth: 5,
              ),
            ),

thank you!

xjc5205 commented 2 years ago

Use a transparent pageView as the middleware. The pageView follows CarouselSlider, and the SmoothPageIndicator follows the pageView

fly-qp commented 1 year ago

Use ValueNotifier in combination with ValueListenableBuilder. In CarouselSlider just implement onPageChanged like this:

onPageChanged: (int index, reason) => _valueNotifier.value = index

And then you can just use AnimatedSmoothIndicator with activeIndex property like this:

ValueListenableBuilder<int>(
  valueListenable: _valueNotifier,
  builder: (BuildContext context, int index, Widget? child) =>
      AnimatedSmoothIndicator(
            activeIndex: index,
            axisDirection: Axis.horizontal,
            count: images.length,
            onDotClicked: _carouselController.animateToPage))
Hemang-Sidapara commented 1 year ago

use AnimatedSmoothIndicator instead of SmoothPageIndicator, there no need of any controller just need to pass activeIndex

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions