1
  • I made slide learning app but slide was looping playing continuously
  • I need to stop auto play it reaches the end.
  • I'm using card_swiper: ^1.0.2
  • I update my full code is here -I'm also using a Assets audio player
  • I try loop: false it won't work
  • Thanks in advance

I don't know how to use it

  import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';

class Chemistry extends StatefulWidget {
  @override
  _ChemistryState createState() => _ChemistryState();
}

class _ChemistryState extends State<Chemistry> {
  List images = [
    'assets/images/che/s.jpg',
    'assets/images/che/t.jpg',
    'assets/images/che/u.jpg',
    'assets/images/che/v.jpg',
    'assets/images/che/w.jpg',
    'assets/images/che/x.jpg',
    'assets/images/che/y.jpg',
    'assets/images/che/z.jpg',
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:Swiper(
          itemCount: images.length,
          loop: false,
          itemBuilder: (BuildContext context, int index) {
            return Padding(
              padding: const EdgeInsets.all(27.0),
              child: Image.asset(
                images[index],
              ),
            );
          },
          indicatorLayout: PageIndicatorLayout.COLOR,
          onIndexChanged: (index) {
            playaudio(index);
          },
          autoplayDelay: 4000,
          autoplay: true,
          pagination: FractionPaginationBuilder(
              color: Colors.red, activeColor: Colors.green, fontSize: 10),
          // control: SwiperControl(),
        ),
      ),

    );
  }
}

void playaudio(index) async {
  AssetsAudioPlayer.newPlayer().open(
    Audio('assets/audio/Chemistry/a$index.mp3'),
  );
}

2 Answers2

0

You can set loop: false - to disable continuous loop mode. If you want autoplay, then set autoplay: true

Rahul Mishra
  • 368
  • 3
  • 9
  • I already try this loop:false but again it looping –  Aug 03 '21 at 11:44
  • If you want to know how to use stopAutoplay(), then 1. You have to create a SwiperController. You can create it just like you create a normal TextEditingController. 2. Then assign the controller to Swiper by its controller method. 3. Then you call it by swiperController.stopAutoPlay(); – Rahul Mishra Aug 03 '21 at 11:53
0

According to the documentation https://pub.dev/packages/card_swiper you can set loop attribute to false

 Swiper(
    itemBuilder: (BuildContext context,int index){
      return Image.network("https://via.placeholder.com/350x150",fit: BoxFit.fill,);
    },
    itemCount: 3,
    loop:false,
    pagination: SwiperPagination(),
  ),
Eanthmue
  • 471
  • 2
  • 5