Flutter 颤振Swiper(视频)
我一直在使用Flutter 颤振Swiper(视频),flutter,dart,flutter-layout,dart-pub,flutter-test,Flutter,Dart,Flutter Layout,Dart Pub,Flutter Test,我一直在使用flatter_swiperpackage来实现一个旋转木马效果,以查看多个图像,它工作正常 现在,我一直计划实现一个旋转木马效果来观看多个视频 我一直在用chuwie观看一段视频,而且效果也不错 然后我尝试将两者结合起来,但效果并没有尽可能一致 首先,您可以在Swiper中查看所有视频。但当你继续来回滑动时,就会出现一个错误 “错误(处理后使用了VideoPlayerController。 在VideoPlayerController上调用dispose()后,将无法再使用它。)“
flatter_swiper
package来实现一个旋转木马效果,以查看多个图像,它工作正常
现在,我一直计划实现一个旋转木马效果来观看多个视频
我一直在用chuwie
观看一段视频,而且效果也不错
然后我尝试将两者结合起来,但效果并没有尽可能一致
首先,您可以在Swiper
中查看所有视频。但当你继续来回滑动时,就会出现一个错误
“错误(处理后使用了VideoPlayerController。
在VideoPlayerController上调用dispose()后,将无法再使用它。)“
我真的需要你的帮助
这是我的朱伊:
class ChewieFeedItem extends StatefulWidget {
// This will contain the URL/asset path which we want to play
final VideoPlayerController videoPlayerController;
final bool looping;
ChewieFeedItem({
@required this.videoPlayerController,
this.looping,
Key key,
}) : super(key: key);
@override
_ChewieFeedItemState createState() => _ChewieFeedItemState();
}
class _ChewieFeedItemState extends State<ChewieFeedItem> {
ChewieController _chewieController;
bool isPlaying = false;
@override
void initState() {
super.initState();
// Wrapper on top of the videoPlayerController
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: widget.videoPlayerController.value.aspectRatio,
// Prepare the video to be played and display the first frame
autoInitialize: true,
looping: widget.looping,
showControls: false,
autoPlay: false,
// Errors can occur for example when trying to play a video
// from a non-existent URL
errorBuilder: (context, errorMessage) {
return Center(
child: Text(
errorMessage,
style: TextStyle(color: Colors.white),
),
);
},
);
}
@override
Widget build(BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Stack(
children: <Widget>[
Chewie(
controller: _chewieController,
),
Container(
alignment: Alignment.center,
child: GestureDetector(
onTap: () {
if (isPlaying) {
_chewieController.pause();
setState(() {
isPlaying = false;
});
} else {
_chewieController.play();
setState(() {
isPlaying = true;
});
}
},
child: Icon(
isPlaying ? FontAwesomeIcons.pause : FontAwesomeIcons.play,
size: 80,
color: Color(colorProxiWall).withOpacity(0.3),
),
),
),
],
),
);
}
@override
void dispose() {
super.dispose();
// IMPORTANT to dispose of all the used resources
widget.videoPlayerController.dispose();
_chewieController.dispose();
}
}
我正在将内容传递到getImageType
,以检查内容是图像还是视频
我的脚本是否适合我
Scaffold _scaffold(ProductDetailApi data, Size size){
videoPlayerController = VideoPlayerController.network(data.gallery[1].url);
chewieController = ChewieController(
videoPlayerController: videoPlayerController,
aspectRatio: 3 / 2,
autoPlay: true,
looping: true,
);
return Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Text(data.products[0].productname),
backgroundColor: Colors.lightBlue,
),
body: Column(children: <Widget>[
//buildImage(data, size),
//buildVideo(chewieController, size),
//_swiper(data, size),
Container(
// A fixed-height child.
height: 150.0,
child: _swiper(data, size),
),
buildSubmitBid(),
buildDescription(data),
SizedBox(height: 10,),
buildChoice(data),
buildLastBidTitle(),
Expanded(
flex: 2,
child: buildLastBid(data),
),
SizedBox(height: 10,),
Container(
margin: EdgeInsets.fromLTRB(10, 0, 10, 0),
child:
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(data.products[0].description,
style: TextStyle(
fontSize: 15
),
)
]
)
)
],)
);
}嗨,你能解决这个问题吗?我已经使用了你的类和视频加载在我的旋转木马,但我得到一个内存泄漏的视频播放控制器。网络。一些帮助将不胜感激。
Scaffold _scaffold(ProductDetailApi data, Size size){
videoPlayerController = VideoPlayerController.network(data.gallery[1].url);
chewieController = ChewieController(
videoPlayerController: videoPlayerController,
aspectRatio: 3 / 2,
autoPlay: true,
looping: true,
);
return Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Text(data.products[0].productname),
backgroundColor: Colors.lightBlue,
),
body: Column(children: <Widget>[
//buildImage(data, size),
//buildVideo(chewieController, size),
//_swiper(data, size),
Container(
// A fixed-height child.
height: 150.0,
child: _swiper(data, size),
),
buildSubmitBid(),
buildDescription(data),
SizedBox(height: 10,),
buildChoice(data),
buildLastBidTitle(),
Expanded(
flex: 2,
child: buildLastBid(data),
),
SizedBox(height: 10,),
Container(
margin: EdgeInsets.fromLTRB(10, 0, 10, 0),
child:
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(data.products[0].description,
style: TextStyle(
fontSize: 15
),
)
]
)
)
],)
);
Swiper _swiper(data, size) {
return Swiper(
outer: false,
itemBuilder: (context, i) {
return Container(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
elevation: 10,
child:
(data.gallery[i].typefile=="IMAGE")?
CachedNetworkImage(
placeholder: (context, url) => CircularProgressIndicator(),
imageUrl: data.gallery[i].url,
fit: BoxFit.fitHeight,
):
Chewie(
controller: chewieController,
)
)
);
},
autoplay: true,
duration: 300,
pagination: new SwiperPagination(margin: new EdgeInsets.all(5.0)),
itemCount: data.gallery.length,
);