无法导航到下一页 PageView
Cannot Navigate To Next Page PageView
我正在使用综合浏览量生成器,但无法遍历页面。我不断收到此错误:
“调用方法 'animateToPage' 时为 null。
接收者:空
尝试调用:animateToPage(1,曲线:'Cubic' 的实例,持续时间:'Duration' 的实例)“
这是我的电话:
PageView.builder(
itemBuilder: (context, i) {
return _prodctReview2(context, i);
},
itemCount: currentReview.order.orderDetails.length,
controller: _pageController,
)
这是我正在调用的函数:
Future nextPage(i) async {
var next = currentPageValue + 1;
print(i);
if (i == currentReview.order.orderDetails.length) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DriverReviewPage(
currentReview: recommendedProducts[i],
)));
} else {
_pageController.jumpToPage(
next,
);
}
}
当我调用该函数时出现此错误
Unhandled Exception:
NoSuchMethodError: The method 'jumpToPage' was called on null.
Receiver: null Tried calling: jumpToPage(1)
我不确定为什么,因为页面已附加。
根据错误,可能 _pageController
没有正确初始化。例如,在有状态的小部件中,您必须在 initState
方法中初始化 _pageController
变量。
@override
void initState(){
_pageController = PageController(initialPage: 0);
}
我正在使用综合浏览量生成器,但无法遍历页面。我不断收到此错误:
“调用方法 'animateToPage' 时为 null。 接收者:空 尝试调用:animateToPage(1,曲线:'Cubic' 的实例,持续时间:'Duration' 的实例)“
这是我的电话:
PageView.builder(
itemBuilder: (context, i) {
return _prodctReview2(context, i);
},
itemCount: currentReview.order.orderDetails.length,
controller: _pageController,
)
这是我正在调用的函数:
Future nextPage(i) async {
var next = currentPageValue + 1;
print(i);
if (i == currentReview.order.orderDetails.length) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DriverReviewPage(
currentReview: recommendedProducts[i],
)));
} else {
_pageController.jumpToPage(
next,
);
}
}
当我调用该函数时出现此错误
Unhandled Exception: NoSuchMethodError: The method 'jumpToPage' was called on null. Receiver: null Tried calling: jumpToPage(1)
我不确定为什么,因为页面已附加。
根据错误,可能 _pageController
没有正确初始化。例如,在有状态的小部件中,您必须在 initState
方法中初始化 _pageController
变量。
@override
void initState(){
_pageController = PageController(initialPage: 0);
}