首页 > 解决方案 > 使用 onscroll 扑动 ontap

问题描述

我正在垂直进行自动滚动,并且在滚动期间我想要应用 Ontap 操作,正如您在示例中看到的那样,我无法记录打印操作:

ps:我已经尝试过该解决方案,但这不是我要在这里寻找的

 @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()
              }
           )
)

谢谢,

标签: flutterdartscroll

解决方案


你会尝试这样做吗

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

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

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

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

推荐阅读