如何抑制 "missing concrete implementation" 警告?
How can a "missing concrete implementation" warning be suppressed?
我该怎么做才能防止编译器抛出以下警告
Missing concrete implementation of setter 'MyClass.field' and getter
'MyClass.field'
关于以下代码?
import 'package:mock/mock.dart';
class MyClass {
String field;
}
@proxy
class MockMyClass extends Mock implements MyClass{}
关于这个警告 (Dart Spec ) :
** 如果具体 class 在其任何超接口中没有方法的实现,除非它声明自己的 noSuchMethod 方法 (10.10),否则这是一个静态警告。
**
因此您可以在 MockMyClass
class.
中为 getter field
创建一个实现
实现noSuchMethod();
当class 有一个noSuchMethod()
时,它会实现任何方法。我认为这也适用于 getter/setter,因为它们只是特殊方法(尽管我自己从未尝试过)。另见 https://www.dartlang.org/articles/emulating-functions/#interactions-with-mirrors-and-nosuchmethod
出现警告是因为您有一个 class 未实现其接口,并且未 声明 一个 noSuchMethod
方法。
仅继承该方法是不够的,您必须在 class 本身中实际声明它。
只需添加:
noSuchMethod(Invocation i) => super.noSuchMethod(i);
那应该关闭 class 的警告。
我该怎么做才能防止编译器抛出以下警告
Missing concrete implementation of setter 'MyClass.field' and getter 'MyClass.field'
关于以下代码?
import 'package:mock/mock.dart';
class MyClass {
String field;
}
@proxy
class MockMyClass extends Mock implements MyClass{}
关于这个警告 (Dart Spec ) :
** 如果具体 class 在其任何超接口中没有方法的实现,除非它声明自己的 noSuchMethod 方法 (10.10),否则这是一个静态警告。 **
因此您可以在 MockMyClass
class.
field
创建一个实现
实现noSuchMethod();
当class 有一个noSuchMethod()
时,它会实现任何方法。我认为这也适用于 getter/setter,因为它们只是特殊方法(尽管我自己从未尝试过)。另见 https://www.dartlang.org/articles/emulating-functions/#interactions-with-mirrors-and-nosuchmethod
出现警告是因为您有一个 class 未实现其接口,并且未 声明 一个 noSuchMethod
方法。
仅继承该方法是不够的,您必须在 class 本身中实际声明它。
只需添加:
noSuchMethod(Invocation i) => super.noSuchMethod(i);
那应该关闭 class 的警告。