0

I am doing an auto-scroll vertically and during the scroll I want I apply an Ontap action, as you see in the example I cannot log the print action:

ps: I have tried that solution but it is not what I am looking for HERE

 @override
  void initState() {
    
    super.initState();
     Future.delayed(Duration(milliseconds: 100)).then((value) {
        if (_scrollController.hasClients)
          _scrollController.animateTo(100,
              duration: Duration(seconds: 5), curve: Curves.ease);
      });
  }

SingleChildScrollView(
            controller: _scrollController,
            scrollDirection: Axis.vertical,
            physics: NeverScrollableScrollPhysics(),
            child: GestureDetector(
              onTap: () {
                print('clicked');
              },
              child: Container()
              }
           )
)

Thanks,

Ayoub Boumzebra
  • 3,885
  • 3
  • 21
  • 37

1 Answers1

0

Would you try to do it this way

SingleChildScrollView(
        controller: _scrollController,
        scrollDirection: Axis.vertical,
        physics: NeverScrollableScrollPhysics(),
        child: GestureDetector(
          onTap: () {
            print('clicked');
          },
          child: Container()
          }
       ),
)

to

GestureDetector gestureDetector = GestureDetector(
child: Container(),
onTap: () => print('clicked'),);

SingleChildScrollView(
        controller: _scrollController,
        scrollDirection: Axis.vertical,
        physics: NeverScrollableScrollPhysics(),
        child: gestureDetector,)

and

Future.delayed(Duration(milliseconds: 100)).then((value) {
    if (_scrollController.hasClients){
      _scrollController.animateTo(100,
          duration: Duration(seconds: 5), curve: Curves.ease);
   gestureDetector.onTap();
  });