[英]flutter : RangeError (index): Invalid value: Valid value range is empty:
[英]Flutter "RangeError (index): Invalid value: Valid value range is empty: 0 with WidgetSpan
我正在尝试在 Flutter 中创建下面的图片。 如您所见,我需要一个链接和一个图像图标。 但是,我在控制台中收到“范围”错误。
这是我的代码片段
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.asset(
"assets/images/checkbox-check.png",
),
Expanded(
child: Container(
child: Wrap(
children: [
RichText(
text: new TextSpan(
children: [
TextSpan(
text: 'Email opportunities. ',
style: TextStyle(
color: Palette.DARK_BLUE, fontSize: 16.0),
),
TextSpan(
text: 'privacy policy',
style: TextStyle(
color: Palette.DARK_BLUE,
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () {
launch();
},
),
TextSpan(
text: ' and ',
),
TextSpan(
text: 'terms of use',
style: TextStyle(
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () {
launch();
},
),
WidgetSpan(
child: Icon(
Icons.info_outline,
color: Colors.red,
),
)
],
),
),
],
),
),
)
],
);
} }
是否有另一种方法来创建我的 UI? 我没有看到错误屏幕,但我在控制台中看到了错误。 我在小部件树中有一个包装,但认为我不需要它。 但同样的问题,如果我删除它。
当您将 TextSpan 与识别器与 WidgetSpan 一起使用时,这是一个 Flutter 问题: https : //github.com/flutter/flutter/issues/51936
一种解决方法是将RichText
包装在ExcludeSemantics
:
ExcludeSemantics(
excluding: true,
child: RichText( ... ),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.