- 我做了一个幻灯片学习应用,但是幻灯片一直在循环播放
- 我需要停止自动播放,它到达结束。
- 我使用
card_swiper: ^1.0.2
- 我更新我的完整代码在这里-我还使用了一个资产音频播放器
- I try loop: false它不会工作
- 提前致谢
我不知道怎么用
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'),
);
}
可以设置loop: false -来关闭连续循环模式。如果你想要自动播放,那么设置autoplay: true
根据文档https://pub.dev/packages/card_swiper,您可以将loop属性设置为false
Swiper(
itemBuilder: (BuildContext context,int index){
return Image.network("https://via.placeholder.com/350x150",fit: BoxFit.fill,);
},
itemCount: 3,
loop:false,
pagination: SwiperPagination(),
),