I am using a PageView.builder to manage a set of 5 pages. The PageView widget allows the user to swipe left/right to navigate between the pages. I can also use a PageController to programatically navigate to different pages, for example at the press of a button. This is all desired behavior. With that said, on the first page I have a form that I would like to validate before allowing the user to continue. With the button, I can just call the form's validation method to check before navigating away, like this:
onPressed: () {
if (_formKey.currentState.validate()) {
//Navigate to next page...
_pageController.nextPage(duration: Duration(milliseconds: 300), curve: Curves.linear);
}
},
My question is: how can I perform this validation before allowing the user to navigate using the swiping gesture?
Thanks