Rakesh Shrivas
Rakesh Shrivas

Reputation: 671

How to solve Failed assertion: line 110 pos 12: '_positions.isNotEmpty': ScrollController not attached to any scroll views

Also get the solution on StackOverflow but it's not working in my case

'_positions.isNotEmpty': ScrollController not attached to any scroll views

PageView throws '_positions.isNotEmpty': ScrollController not attached to any scroll views

Widget _buildIntroSlider() {
            return Container(
              padding: EdgeInsets.symmetric(horizontal: 46.0),
              child: Stack(
                alignment: AlignmentDirectional.bottomCenter,
                children: <Widget>[
                  PageView.builder(
                    scrollDirection: Axis.horizontal,
                    controller: _pageController,
                    onPageChanged: _onPageChanged,
                    itemCount: slideList.length,
                    itemBuilder: (ctx, i) =>
                        SlideItem(slide: slideList[i], bold: false),
                  ),
                 
                ],
              ),
            );
          }

Upvotes: 7

Views: 6414

Answers (1)

Isti01
Isti01

Reputation: 873

Whenever you use the PageController, you need to keep in mind that if you try to access the PageController data, like the current index before the PageView with that specific controller is rendered, you will get this error. You can check if it is aleady built with

_pageController.hasClients

and if not, you cannot call any other methods of the controller otherwise it will throw an error.

Upvotes: 14

Related Questions