【问题标题】:How can I implement tap-able Text widget, Flutter?如何实现可点击的文本小部件 Flutter?
【发布时间】:2021-06-09 07:59:35
【问题描述】:

我有一个文本小部件,按下它必须显示另一条路线。但是我看不到 Text 小部件的任何 onPressed() 方法。请帮忙。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    尝试使用 TextButton 小部件:

    TextButton(
                onPressed: () {},
                child: Text('Simple Button'),
              ),
    

    【讨论】:

      【解决方案2】:

      在你的情况下,你可以去多条路线。

      1. 使用材质TextButton:

        TextButton(onPressed: () {}, child: Text('Your child'))

      2. 使用 InkWell 小部件,它使用“按钮”属性、飞溅等覆盖您的小部件,从而允许您拥有更多可自定义的按钮点击:

        InkWell(onTap: () {}, onDoubleTap: () {}, onLongPress: () {}, onHover: () {}, ..etc , child: Text('Your child widget'))

      3. 使用 GestureDetector,是您可以提供的任何手势的最可定制的解决方案(从它的名称来看),可以处理点击、长按、双击、拖动等。 语法类似:

        GestureDetector(onTap: () {}, child: Text('Your child widget'))

      【讨论】:

        【解决方案3】:

        使任何小部件可点击的最佳方法是使用GestrureDetector,您只需将其放在您想要的小部件/小部件之外,您就可以使用dozen of properties。 例如

        GestureDetector(child:
        
         onPressed: () {},
        
         Text('Your text')
        
        )
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-07-05
          • 2022-07-22
          • 2020-12-11
          • 2017-02-10
          • 1970-01-01
          • 2019-03-13
          • 2017-11-12
          相关资源
          最近更新 更多