0
votes

I've got a PageView.builder within a StatelessWidget. Each page gets a SwipeGestureRecognizer which provides a Navigator.pop(context) onSwipeDown. But I'd like this gesture to only trigger when the user scrolls back to initialPage: 0. For the rest of the pages I'd like the default scrolling provided by the PageView.builder. I've managed to get this nearly working except the presence of the SwipeGestureRecognizer seems to disable the normal swipe down default scrolling of the PageViewer on all the other pages. How can I get the swipe down gesture to activate only on the first page?

  class StageBuilder extends StatelessWidget {
  final List<SpeakContent> speakcrafts;
  StageBuilder(this.speakcrafts);    
  final PageController controller = PageController(initialPage: 0);

  @override
  Widget build(context) {
    return PageView.builder(
      controller: controller,
      itemCount: speakcrafts.length,
      itemBuilder: (context, int currentIndex) {
        return createViewItem(speakcrafts[currentIndex], context, currentIndex);
      },
    );
  }

  Widget createViewItem(SpeakContent speakcraft, BuildContext context, int currentIndex) {
  
    return (
        Container(
        child: SwipeGestureRecognizer(some stuff)
        ),
     );
  }
}

onSwipeDown:() {
    if (currentIndex==0)
    Navigator.pop(context);
            },
1

1 Answers

0
votes

So here's what I did;

 child: SwipeGestureRecognizer(

  onSwipeUp: () {

       controller.nextPage(duration: const Duration(milliseconds: 400), curve: Curves.ease);

       },

  onSwipeDown: () {

       (currentIndex == 0)?

       Navigator.pop(context):

       controller.previousPage(duration: const Duration(milliseconds: 400), curve: Curves.ease);

  },

...)