使用RichText和TextSpan以及GestureRecognizer。使用GestureRecognizer
可以检测轻击、双击、长按等手势。
Widget build(BuildContext context) {
TextStyle defaultStyle = TextStyle(color: Colors.grey, fontSize: 20.0);
TextStyle linkStyle = TextStyle(color: Colors.blue);
return RichText(
text: TextSpan(
style: defaultStyle,
children: <TextSpan>[
TextSpan(text: 'By clicking Sign Up, you agree to our '),
TextSpan(
text: 'Terms of Service',
style: linkStyle,
recognizer: TapGestureRecognizer()
..onTap = () {
print('Terms of Service"');
}),
TextSpan(text: ' and that you have read our '),
TextSpan(
text: 'Privacy Policy',
style: linkStyle,
recognizer: TapGestureRecognizer()
..onTap = () {
print('Privacy Policy"');
}),
],
),
);
}
package:flutter/gestures.dart';
。 - engelen..
这个符号,我以前没见过。 - Mrak Vladarnice concept of help/support - https://support.google.com/firebase?authuser=0#topic=6399725
,现在请告诉我如何在Flutter中将此字符串中的URL转换为链接?非常感谢。 - KamleshRichText
将一系列TextSpan
合并成一个文本。 return RichText(
text: TextSpan(
text: 'Hello ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(
text: 'world!',
style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(
text: ' click here!',
recognizer: TapGestureRecognizer()
..onTap = () => print('click')),
],
),
);
TapGestureRecognizer
的onTap()
方法,但仍然将其实例返回到TextSpan
的recognizer
属性。 - haroldolivierinice concept of help/support - https://support.google.com/firebase?authuser=0#topic=6399725
,现在请告诉我如何在Flutter中将此字符串中的URL转换为链接?非常感谢。 - Kamlesh