Milad-Akarie / smooth_page_indicator

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

Missing infinite loop support #79

Closed Kal-Elx closed 4 months ago

Kal-Elx commented 6 months ago

First of all, thanks for a great package!

This package is missing infinite loop support as advertised in the README or instructions for how to enable it. This GIF suggests that there has been support in the past.

As you can see the animation goes through all the dots instead of just animating between the first and last.

https://github.com/Milad-Akarie/smooth_page_indicator/assets/41339152/cdd5a5fa-3824-4d82-b82b-7b3b9e6c6984

It would be amazing if this could be fixed.

Here's a minimal example using AnimatedSmoothIndicator.

import 'package:flutter/material.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: MyHomePage());
  }
}

const _kPageCount = 5;

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _index = 0;

  void _increment() {
    setState(() {
      _index = (_index + 1) % _kPageCount;
    });
  }

  void _decrement() {
    setState(() {
      _index = (_index - 1) % _kPageCount;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          AnimatedSmoothIndicator(
            activeIndex: _index,
            count: _kPageCount,
            effect: const WormEffect(),
          ),
          AnimatedSmoothIndicator(
            activeIndex: _index,
            count: _kPageCount,
            effect: const JumpingDotEffect(),
          ),
          AnimatedSmoothIndicator(
            activeIndex: _index,
            count: _kPageCount,
            effect: const ScrollingDotsEffect(),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              ElevatedButton(
                onPressed: _decrement,
                child: IconButton(
                  icon: const Icon(Icons.remove),
                  onPressed: _decrement,
                ),
              ),
              ElevatedButton(
                onPressed: _increment,
                child: IconButton(
                  icon: const Icon(Icons.add),
                  onPressed: _increment,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
Milad-Akarie commented 4 months ago

@Kal-Elx should be fixed in v1.2.0

Kal-Elx commented 4 months ago

Hi @Milad-Akarie! Thanks for having a look. I updated to v1.2.0 but the problem still persists for me. Can you reopen the issue. If it works for you, can you provide an example where it works and I can use that to debug my code?

Milad-Akarie commented 4 months ago

@Kal-Elx you need to pass the index as is, without taking away the reminder

  void _increment() {
    setState(() {
      _index = (_index + 1) ;
    });
  }

  void _decrement() {
    setState(() {
      _index = (_index - 1);
    });
  }