Flutter 转盘无法在颤振中自动滑动
我正在尝试创建自动滑动旋转木马。在我遇到“PageController.page在生成PageView之前无法访问”的问题之前 我可以从参考资料中解决它 但不幸的是,旋转木马不能自动滑动。请帮帮我 在carousel_pro.dart中,我有如下类似程序的更改:Flutter 转盘无法在颤振中自动滑动,flutter,Flutter,我正在尝试创建自动滑动旋转木马。在我遇到“PageController.page在生成PageView之前无法访问”的问题之前 我可以从参考资料中解决它 但不幸的是,旋转木马不能自动滑动。请帮帮我 在carousel_pro.dart中,我有如下类似程序的更改: final _controller = new PageController(); @override void initState() { super.initState(); if (_controller.hasClients)
final _controller = new PageController();
@override
void initState() {
super.initState();
if (_controller.hasClients) {
if (widget.autoplay) {
new Timer.periodic(widget.autoplayDuration, (_) {
if (_controller.page.round() == widget.images.length-1) {
_controller.animateToPage(
0,
duration: widget.animationDuration,
curve: widget.animationCurve,
);
} else {
_controller.nextPage(
duration: widget.animationDuration,
curve: widget.animationCurve);
}
});
}
}
}
您必须检查小部件是否有图像
if (widget.images != null && widget.images.isNotEmpty) {
if (widget.autoplay) {
Timer.periodic(widget.autoplayDuration, (_) {
if (_controller.hasClients) {
if (_controller.page.round() == widget.images.length - 1) {
_controller.animateToPage(
0,
duration: widget.animationDuration,
curve: widget.animationCurve,
);
} else {
_controller.nextPage(
duration: widget.animationDuration,
curve: widget.animationCurve);
}
}
});
}
}
你还必须重新安装应用程序。
它为我工作