TextButton 小部件需要双击标签才能进入下一页

TextButton widget requires double tab to go on next page

我正在使用 PageView 小部件并且在 pageview 小部件中有很多子项,为了在页面之间导航,我正在使用 PageController(跳转到页面)但是由于某些未知原因,TextButton 需要双进入下一页,反之亦然进入上一页

你能告诉我我做错了什么吗?

class _DemoState extends State<Demo> {

  int argsNumber = 8;

  final PageController controller = PageController(initialPage: 0);

  int pageChanged = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: PageView(
          controller: controller,
          onPageChanged: (value){
             setState(() {
               pageChanged = value;
             });
          },
          children: [
            Container( // Children One
              child: Column(
                children: [
                  Expanded(child: Text('text'.tr(), style: TextStyle(fontSize: 25.0, height: 1.6, fontWeight: FontWeight.bold, color: Colors.white, fontFamily: 'oswald'), textAlign: TextAlign.center)),
                  Row(
                    children: [
                      TextButton(
                          onPressed: (){
                            controller.jumpToPage(pageChanged++); // To go on the next page but requires double tap
                          },
                          child: Icon(Icons.arrow_forward, color: Colors.white,)
                      ),
                      TextButton(
                          onPressed: (){
                            controller.jumpToPage(pageChanged--);
                          },
                          child: Icon(Icons.arrow_back, color: Colors.white,)
                      ),
                    ],
                  ),
                ],
              ),
            ),
            for(int i = 0; i < arguments.length; i += argsNumber ) // Children Two (loop)
              Lyrics(arguments[i].tr(), arguments[i + 1].tr(), arguments[i + 2].tr(), arguments[i + 3].tr(), arguments[i + 4].tr(), arguments[i + 5].tr(), arguments[i + 6].tr(), arguments[i + 7].tr(), controller, pageChanged),
            Container( // Children Three
              child: Column(
                children: [
                  Text('text'.tr(), style: TextStyle(fontSize: 25.0, height: 1.6, fontWeight: FontWeight.bold, color: Colors.white, fontFamily: 'oswald'), textAlign: TextAlign.center,),
                  Row(
                    children: [
                      TextButton(
                          onPressed: (){
                            controller.jumpToPage(pageChanged++); // To go on the next page but requires double tap
                          },
                          child: Icon(Icons.arrow_forward, color: Colors.white,)
                      ),
                      TextButton(
                          onPressed: (){
                            controller.jumpToPage(pageChanged--);
                          },
                          child: Icon(Icons.arrow_back, color: Colors.white,)
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

尝试像这样增加数字:

            TextButton(
                          onPressed: (){
                            pageChanged = pageChanged + 1;
                            controller.jumpToPage(pageChanged);
                          },
                          child: Icon(Icons.arrow_forward, color: Colors.white,)
                      ),
                      TextButton(
                          onPressed: (){
                            pageChanged = pageChanged - 1;
                            controller.jumpToPage(pageChanged);
                          },
                          child: Icon(Icons.arrow_back, color: Colors.white,)
                      )

我建议您使用手势检测器而不是 TextBotton,并在容器的子项中重新创建一个按钮。

这样你也可以使用doubleTap属性,就是你要找的

GestureDetector(
    onDoubleTap: _handleDoubleTap,
    child: Container(
       ... 
     ),
);

参考:
GestureDetector