首页 > 解决方案 > 我们可以在颤动中设置一个可点击的 SpanText 吗?

问题描述


      RichText(
        text: TextSpan(
          text: 'NEW USER ?',
          style: TextStyle(color: Colors.grey),
          children: <TextSpan>[
            TextSpan(
              text: '  SIGN UP',
              style: TextStyle(color: Colors.blue),
            )
          ],
        ),
      ),

在这里,我想在点击“SIGN UP”时做一些事情。

标签: flutter

解决方案


TextSpan具有recognizer可以点击给定小部件的属性。

TextSpan(
         text: '  SIGN UP',
         style: TextStyle(color: Colors.blue),
         )    
recognizer: TapGestureRecognizer()
            ..onTap = () {
            // do something here
    }),
)

推荐阅读