prefs.setStringList -> gt; gt; gt;错误:参数列表< string?>可以分配给参数类型列表< string>
您好,我尝试进行无效的安全迁移,但是
prefs.setStringList("save_list_autre2",save_list.toList());
错误的问题是:参数列表< string?>无法分配到参数类型列表
RegExp regExp = new RegExp(r'(...)');
var save_list= regExp.allMatches(decrypted).map((z) => z.group(0));
if(regExp.allMatches(decrypted)==null ){
[...]
} else {
prefs.setStringList("save_list_autre2",save_list.toList());
}
我添加.toString()
来自save_list = regexp.allMatches(解密).map((z)=> z.group(0) .tostring());
删除了错误,但我不知道这是否是好的解决方案
Hello I try to make null safety migration, but have a probleme with
prefs.setStringList("save_list_autre2",save_list.toList());
the error is : the argument list<String?> can't be assigned to the parameter type List
RegExp regExp = new RegExp(r'(...)');
var save_list= regExp.allMatches(decrypted).map((z) => z.group(0));
if(regExp.allMatches(decrypted)==null ){
[...]
} else {
prefs.setStringList("save_list_autre2",save_list.toList());
}
I add .toString()
from save_list= regExp.allMatches(decrypted).map((z) => z.group(0).toString());
the error is removed but I don't know if it's the good solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您调用
z.group(0)
时,如果没有给定索引的组(在这种情况下为0),则group
方法可以返回null。因此,DART认为您的字符串列表中可能有一些无效的值。现实是,您不应该获取任何零值,因为您要通过0。因此,告诉DART该方法不返回null,请使用
!
操作员:如果有机会,您碰巧有任何零值,那么此代码将行不通(正如我说的,我相信您不会,但我知道什么?我从来没有用Dart使用过Regexes
) ,您首先需要过滤零值,然后使用
!
:希望这足以解决问题
When you call
z.group(0)
thegroup
method could return null if there was no group with the given index (0 in this case). so dart thinks you might have some null values on your list of strings.The reality is that you shouldn't get any null values because you are passing a 0. So to tell dart that the method isn't returning null, use the
!
operator:If, by some chance, you happened to have any null values, this code will not work (as I said, I believe you won't but what do I know? I've never used regexes with dart)
If that's the case, you first need to filter the null values and then use the
!
:Hopefully that's enough to fix the problem