You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter运行报错:flutter_pagewise包List?调用removeWhere空安全问题

Flutter运行错误:List?类型无法调用removeWhere方法

/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_pagewise-2.0.3/lib/flutter_pagewise.dart:510:23: Error: Method 'removeWhere' cannot be called on 'List?' because it is potentially null.
'List' is from 'dart:core'.
Try calling using ?. instead.
this._loadedItems.removeWhere(test);
^^^^^^^^^^^

  • 错误核心:this._loadedItems是List?潜在可空类型,无法直接调用removeWhere方法
  • Dart官方修复建议:使用?.操作符替代直接调用

具体修复方案

修改flutter_pagewise.dart文件第510行的代码:

// 原代码
this._loadedItems.removeWhere(test);

// 修改后代码
this._loadedItems?.removeWhere(test);

如果能确保_loadedItems绝对不会为null,也可以使用非空断言(不推荐,存在空安全风险):

this._loadedItems!.removeWhere(test);

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 11:55:24