prefs.setStringList -> gt; gt; gt;错误:参数列表< string?>可以分配给参数类型列表< string>

发布于 2025-02-07 03:33:00 字数 576 浏览 1 评论 0原文

您好,我尝试进行无效的安全迁移,但是

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尴尬癌患者 2025-02-14 03:33:00

当您调用z.group(0)时,如果没有给定索引的组(在这种情况下为0),则group方法可以返回null。因此,DART认为您的字符串列表中可能有一些无效的值。

现实是,您不应该获取任何零值,因为您要通过0。因此,告诉DART该方法不返回null,请使用操作员:

regExp.allMatches(decrypted)
  .map((z) => z.group(0)!)

如果有机会,您碰巧有任何零值,那么此代码将行不通(正如我说的,我相信您不会,但我知道什么?我从来没有用Dart使用过Regexes

) ,您首先需要过滤零值,然后使用

regExp.allMatches(decrypted)
  .map((z) => z.group(0))
  .where((v) => v != null) // filter out null values
  .map((v) => v!); // let dart know you don't have any null values.

希望这足以解决问题

When you call z.group(0) the group 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:

regExp.allMatches(decrypted)
  .map((z) => z.group(0)!)

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 !:

regExp.allMatches(decrypted)
  .map((z) => z.group(0))
  .where((v) => v != null) // filter out null values
  .map((v) => v!); // let dart know you don't have any null values.

Hopefully that's enough to fix the problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文