RichText使用
RichText(
text: TextSpan(
text: '登陆即同意',
style: TextStyle(fontSize: 14, color: Colors.black),
children: [
TextSpan(
text: '"服务条款"',
style: TextStyle(fontSize: 14, color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () {
print('点击了服务条款');
},
),
TextSpan(
text: '和',
style: TextStyle(fontSize: 14, color: Colors.black),
),
TextSpan(
text: '"隐私政策"',
style: TextStyle(fontSize: 14, color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () {
print('点击了隐私政策');
},
),
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Image.asset(
'assets/noavatar.png',
width: 20,
height: 20,
),
),
],
),
),
TextSpan可以用来显示文字类型,设置文字颜色,点击事件等
TextSpan(
text: '"隐私政策"',
style: TextStyle(fontSize: 14, color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () {
print('点击了隐私政策');
},
),
WidgetSpan 可以用来显示任意widget,图片按钮等等
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Image.asset(
'assets/noavatar.png',
width: 20,
height: 20,
),
),