对于每个 ->返回 true;错误 返回类型 'bool' 不是"void",如要求



你好,我试图使null安全迁移,但我有一个错误与forEach循环谁返回返回真。我不知道如何在空状态下正确书写。谢谢你

String sanitize(
String input, List<String> possibleStart, List<String> possibleEnd) {
final String start = possibleStart.join("|");
final String end = possibleEnd.join("|");
final RegExp exp = RegExp("(?<=$start)(.*?)(?=$end)");
final Iterable<Match> matches = exp.allMatches(input);

matches.forEach((match) {
input =
input.replaceFirst(match.group(0)!, match.group(0)!.replaceAll(",", "§").replaceAll(":", "ø").replaceAll("/", "å"));
return true;  // error The return type 'bool' isn't a 'void', as required by the closure's context dart flutter
});
return input;
}

forEach函数不应该返回任何东西,您可以从iterable.dart

中看到它
void forEach(void action(E element)) {
for (E element in this) action(element);
}

最新更新