implicit_call_tearoffs
當將物件用作 Function 時,顯式地對其 call 方法進行撕裂。
詳情
#要 在將物件賦值給 Function 型別時,顯式地對其 .call 方法進行撕裂。顯式撕裂減少了隱晦性。未來的語言版本可能會移除隱式的 call 撕裂。
不推薦
dart
class Callable {
void call() {}
}
void callIt(void Function() f) {
f();
}
callIt(Callable());推薦
dart
class Callable {
void call() {}
}
void callIt(void Function() f) {
f();
}
callIt(Callable().call);啟用
#要啟用 implicit_call_tearoffs 規則,請在您的 analysis_options.yaml 檔案中,將 implicit_call_tearoffs 新增到 linter > rules 下
analysis_options.yaml
yaml
linter:
rules:
- implicit_call_tearoffs如果您使用的是 YAML map 語法來配置 linter 規則,請在 linter > rules 下新增 implicit_call_tearoffs: true。
analysis_options.yaml
yaml
linter:
rules:
implicit_call_tearoffs: true