You need to enable JavaScript to run this app. Flutter调用AlertDialog弹窗时触发RangeError:仅允许有效索引0却取值1
优惠活动
大模型
产品
解决方案
定价
更多

Flutter调用AlertDialog弹窗时触发RangeError:仅允许有效索引0却取值1

功能开发与问题反馈

已完成的开发内容

  • 已实现基础弹窗交互功能,对应代码仓库地址为 first
  • 弹窗核心实现代码如下:
void newAlert(BuildContext context) {
  showDialog(
    context: context,
    builder: (BuildContext context){
      return AlertDialog(
        title: Text('title text'),
        content: Text('content text'),
        actions: [
          FlatButton(
            onPressed: (){
              Navigator.of(context).pop();
            },
            child: Text('dismiss'),
          ),
        ],
      );
    },
  );
}
  • 已完成弹窗函数所在文件的导入流程,在main.dart中完成相关依赖引入,页面通过RaisedButton的点击事件触发弹窗调用,触发逻辑代码如下:
body: RaisedButton(
        child: Text('Alert'),
        onPressed: () {
          newAlert(context);
        }),
...

真机运行异常

在真机环境下点击触发按钮时,应用持续抛出手势库捕获的异常,完整异常日志如下:

======== Exception caught by gesture library ================
The following RangeError was thrown while routing a pointer event:
RangeError (index): Invalid value: Only valid value is 0: 1

内容的提问来源于stack exchange,提问作者Mohammad Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.04 12:24:03