【发布时间】:2021-06-11 20:43:29
【问题描述】:
在 PageViewBuilder 中,我想使用我在 pub.dev 上找到的 ArgonTimerButton 上的 onTap 移动到下一页,而不是滑动手势。我创建了一个控制器并使用了 controller.nextPage() 但它给了我这个错误:
'positions.isNotEmpty': PageController.page cannot be accessed before a PageView is built with it.
我的代码:
final controller = PageController();
@override
Widget build(BuildContext context) {
MediaQueryData size = MediaQuery.of(context).size;
return PageView.builder(
physics: NeverScrollableScrollPhysics(),
controller: PageController(),
itemCount: widget.workoutExcercises.length,
itemBuilder: (context, index) {
return
//other widgets
ArgonTimerButton(
initialTimer: 3, // Optional
height: 50,
width: size.width * 0.55,
minWidth: width * 0.40,
color: Colors.white,
borderRadius: 5.0,
curve: Curves.easeInToLinear,
child: Text(
"Done?",
style: TextStyle(
color: Colors.black,
fontSize: 24,
fontWeight: FontWeight.w700),
),
loader: (timeLeft) {
return Text(
"Rest Time | $timeLeft",
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w700),
);
},
onTap: (startTimer, btnState) {
if (btnState == ButtonState.Idle) {
controller.nextPage(duration: Duration(milliseconds:1000), curve: Curves.easeInToLinear);
}
},
),
],
),
);
},
);
我该如何解决这个问题?
【问题讨论】: