I get the following error when I try to invoke _pagecontroller.jumpToPage
or _pagecontroller.animateToPage
:
Exception has occurred.
_AssertionError (‘package:flutter/src/widgets/scroll_controller.dart’: Failed assertion: line 157 pos 12: ‘_positions.isNotEmpty’:
ScrollController not attached to any scroll views.)
it throws the error in this block of code:
void navigateToPage(int index) {
log(index.toString());
_pageController.jumpToPage( <----- here
index,
// duration: Duration(milliseconds: 300),
// curve: Curves.linear,
);
}
I’m trying to learn flutter and not really familiar with the terminology, but what I have is the main.dart file that has the following stack for the build widget:
Widget build(BuildContext context) {
return PageControllerManager(
child: Scaffold(
appBar: AppBar(
elevation: 8.0,
backgroundColor: drawerBackgroundColor,
title: const Text(
"Photographers Assistant",
),
),
body: Stack(
children: [
PageView.builder(
controller: PageControllerProvider.of(context)?.pageController,
onPageChanged:
PageControllerProvider.of(context)?.onPageChanged,
physics: const NeverScrollableScrollPhysics(),
// onPageChanged: (int page) {
// setState(() {
// _activePage = page;
// });
// },
itemCount: _pages.length,
itemBuilder: (BuildContext context, int index) {
return _pages[index % _pages.length];
}),
const CollapsingNavigationDrawer()
],
),
),
);
I also have a collapsing navigation drawer that has the following on-tap:
onTap: () {
navigationItems[counter].onTap();
setState(() {
currentSelectedIndex = counter;
});
PageControllerProvider.of(context)
?.navigateToPage(counter);
if i comment the following in the navigation_drawer_widget.dart file, the error goes away but of course no page change happens:
PageControllerProvider.of(context)
?.navigateToPage(counter);
When the tap happens it throws that error and the new “page” is not loaded into the body of the main.dart file. I’m not trying to scroll or anything, just trying to load in another page when I click the items in the navigation drawer. What am i doing wrong?