Flutter实现Android的SpannableString效果

Flutter实现Android的SpannableString效果

图片是网上找的,具体实现如下:

_buildClause() {
    return Padding(
      padding: const EdgeInsets.only(bottom: 20.0),
      child: RichText(
          maxLines: 2,
          text: TextSpan(
              text: '完成登录即代表您已阅读并同意"',
              style: TextStyle(fontSize: 14.0, color: Colors.grey),
              children: <TextSpan>[
                TextSpan(
                    text: '服务条款',
                    style: TextStyle(
                        fontSize: 14.0,
                        color:Color(0xFFD37957),
                        decoration: TextDecoration.underline
                    ),
                    recognizer: recognizer),
                TextSpan(
                    text: '"',
                    style: TextStyle(fontSize: 14.0, color: Colors.grey),
                    )

          ])),
    );
  }

注意:TextStyle是设置文字的样式,TextDecoration的属性,比如

lineThrough 在每行文字中画一条线 (删除线) 
none 不做任何事情 
overline 在每行文本上方画一条线 (上划线) 
underline 在每行文本下面画一条线(下划线)

要实现点击高亮文字需要一个:TapGestureRecognizer

final TapGestureRecognizer recognizer = TapGestureRecognizer();

然后在initState里面进行监听

recognizer.onTap = () {
  _goCluasePage();
};