当我运行当前代码时…我得到这个错误:
UnimplementedError (UnimplementedError: init() has not been implemented.)
- 在手机上显示所有非常减速显示,但没有发现错误!*
编码:
final videos = [
'assets/videos/Frozen_Flower_In_Ice_1402.mp4',
'assets/videos/Main_EarthPlanet.mp4',
];
class VideosScreen extends StatefulWidget {
const VideosScreen({super.key});
@override
State<VideosScreen> createState() => _VideosScreenState();
}
class _VideosScreenState extends State<VideosScreen> {
late PageController _pageController;
@override
void initState() {
super.initState();
_pageController = PageController(viewportFraction: 0.8);
}
@override
void dispose() {
_pageController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return PageView.builder(
controller: _pageController,
itemCount: videos.length,
itemBuilder: (context, index) {
return VideoCard(
assetPath: videos[index],
);
},
);
}
}
class VideoCard extends StatefulWidget {
const VideoCard({
super.key,
required this.assetPath,
});
final String assetPath;
@override
State<VideoCard> createState() => _VideoCardState();
}
class _VideoCardState extends State<VideoCard> {
late VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.asset(widget.assetPath);
_controller
..addListener(() => setState(() {}))
..setLooping(true)
..setVolume(0)
..initialize().then((_) => setState(() {}))
..play();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedContainer(
duration: const Duration(milliseconds: 250),
margin: const EdgeInsets.symmetric(vertical: 32, horizontal: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
offset: const Offset(0, 6),
blurRadius: 8,
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
),
),
);
}
}
在视频错误不!
还有...当我在Chrome中启动应用程序时...应用程序不减速显示在显示器上,因为在手机中,虽然ram内存过剩.
设置持续时间和重写的代码和较低的fps...没有任何帮助。
1条答案
按热度按时间koaltpgm1#
我建议把图片不超过60秒,不超过60 fps。
祝大家好运)