已编辑:此错误仅在 IOS 设备上出现,在 android 上没有问题。
当我滚动 AlertDialog 时,RangeError 被捕获。我有更多带有纯文本的 AlertDialogs,没有这样的问题。 滚动时,错误一直被抛出。我知道有类似的问题,但它们都使用构建器并且可以定义 Itemcount。
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
elevation: 20,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
content: Container(
width: double.maxFinite,
height: 130,
child: ListView(children: <Widget>[
RichText(
text: TextSpan(children: [
TextSpan(
text: 'Feedback:',
style: TextStyle(color: Colors.black)),
TextSpan(
text: "\n",
style: TextStyle(color: Colors.black)),
WidgetSpan(
child: Icon(
Icons.email,
size: 15,
)),
TextSpan(
text:
' email@outlook.com' + "\n",
style: TextStyle(color: Colors.black)),
TextSpan(
text: "\n",
style: TextStyle(color: Colors.black)),
TextSpan(
text: 'Updates:',
style: TextStyle(color: Colors.black)),
TextSpan(
text: "\n",
style: TextStyle(color: Colors.black)),
WidgetSpan(
child: Icon(
Icons.link,
size: 15,
)),
TextSpan(
text: ' ',
style: TextStyle(color: Colors.black)),
TextSpan(
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
text: 'Instagram' + "\n",
recognizer: TapGestureRecognizer()
..onTap = () async {
var url =
"https://www.instagram.com/";
if (await canLaunch(url)) {
await launch(url);
} else {
throw "Cannot load Url";
}
}),
TextSpan(
text: "\n",
style: TextStyle(color: Colors.black)),
TextSpan(
text: 'Support',
style: TextStyle(color: Colors.black)),
TextSpan(
text: "\n",
style: TextStyle(color: Colors.black)),
WidgetSpan(
child: Icon(
Icons.payment,
size: 15,
)),
TextSpan(
text: ' ',
style: TextStyle(color: Colors.black)),
TextSpan(
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
text: 'Paypal',
recognizer: TapGestureRecognizer()
..onTap = () async {
var url =
"https://www.paypal.me/";
if (await canLaunch(url)) {
await launch(url);
} else {
throw "Cannot load Url";
}
}),
]))
]),
),
);
});
遵循错误和堆栈跟踪:
======== Exception caught by scheduler library =====================================================
The following RangeError was thrown during a scheduler callback:
RangeError (index): Invalid value: Valid value range is empty: 0
When the exception was thrown, this was the stack:
#0 List.[] (dart:core-patch/growable_array.dart:177:60)
#1 List.elementAt (dart:core-patch/growable_array.dart:386:16)
#2 RenderParagraph.assembleSemanticsNode (package:flutter/src/rendering/paragraph.dart:921:50)
#3 _SwitchableSemanticsFragment.compileChildren (package:flutter/src/rendering/object.dart:3717:13)
#4 _SwitchableSemanticsFragment.compileChildren (package:flutter/src/rendering/object.dart:3709:16)
...
其他一切正常。感谢您的帮助!