您好,我嘗試進行空安全遷移,但我有一個回傳 true 的 forEach 回圈錯誤。我不知道如何在 null stafety 中正確書寫。謝謝
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;
}
uj5u.com熱心網友回復:
函式 forEach 不應該回傳任何內容,您可以從 iterable.dart 中看到它
void forEach(void action(E element)) {
for (E element in this) action(element);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/489962.html
標籤:扑
