【发布时间】:2021-01-27 07:06:55
【问题描述】:
我正在尝试为内联文本链接做一个无状态小部件。
我在这里使用这个答案https://stackoverflow.com/a/55607224/3808307 来创建链接
RichText(
text: TextSpan(
children: [
TextSpan(text: 'This is a going to be a Text which has '),
TextSpan(
text: 'single tap',
style: style,
recognizer: TapGestureRecognizer()
..onTap = () {
// single tapped
},
),
TextSpan(text: ' along with '),
TextSpan(
text: 'double tap',
style: style,
recognizer: DoubleTapGestureRecognizer()
..onDoubleTap = () {
// double tapped
},
),
TextSpan(text: ' and '),
TextSpan(
text: 'long press',
style: style,
recognizer: LongPressGestureRecognizer()
..onLongPress = () {
// long pressed
},
),
],
),
)
,但我想要一个可以导入的 TextSpan,并且已经应用了样式,并传递了一个可以作为标签和函数的文本。
我需要一个有状态的小部件,还是我可以只使用一个无状态的小部件?
【问题讨论】: