0

I have a class like this :

class MyController {
  static PageController globalController = PageController(initialPage: 0);

  void diispose() {
    globalController.dispose();
  }
}

I'd like to use this PageController in two different locations to modify thePageView however after use MyController.globalController.jumpToPage(1); I got this error :

ScrollController attached to multiple scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
package:flutter/…/widgets/scroll_controller.dart:1
Failed assertion: line 108 pos 12: '_positions.length == 1'

1 Answer 1

1

I think you cannot use the same PageController for two scroll views, but you can create one for each scroll and one method that jump all scrolls to page, as the example below:

class MyController {
  static PageController globalControllerOne = PageController(initialPage: 0);
  static PageController globalControllerTwo = PageController(initialPage: 0);

  void jumpToPage(int page) {
    globalControllerOne.jumpToPage(page);
    globalControllerTwo.jumpToPage(page);
  }

  void dispose() {
    globalController.dispose();
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

In my case, I'd like to control a single PageView from two different locations using a single PageController connected to my widget. For example, I'd like to have a button somewhere in my app that changes the BottomNavigationBar items using PageController.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.