implicit_call_tearoffs
隱式拆分 'call' 方法。
描述
#當具有 call 方法的物件被賦值給函式型別變數時,分析器會產生此診斷資訊,這表示隱式拆分了 call 方法。
示例
#以下程式碼會產生此診斷資訊,因為 Callable 的例項被傳遞給了期望 Function 型別的函式
dart
class Callable {
void call() {}
}
void callIt(void Function() f) {
f();
}
void f() {
callIt(Callable());
}常見修復方法
#顯式拆分 call 方法
dart
class Callable {
void call() {}
}
void callIt(void Function() f) {
f();
}
void f() {
callIt(Callable().call);
}