我正在尝试为嵌入式文本链接做一个无状态的小部件。
我在这里使用这个答案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,并且已经应用了样式,并向其传递了可以充当标签和函数的文本。
我是否需要一个有状态的小部件,还是可以只使用无状态的小部件?
您可以毫无问题地使用无状态窗口小部件。
如果您在按链接时需要更改文本样式,则需要使用有状态的小部件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句