Reputation: 329
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'
Upvotes: 0
Views: 322
Reputation: 566
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();
}
}
Upvotes: 1