我该怎么做才能防止编译器抛出以下警告
缺少 setter 'MyClass.field' 和 getter 'MyClass.field' 的具体实现
在下面的代码?
import 'package:mock/mock.dart';
class MyClass {
String field;
}
@proxy
class MockMyClass extends Mock implements MyClass{}
Run Code Online (Sandbox Code Playgroud)
实现noSuchMethod();当一个类有一个时,noSuchMethod()它实现了任何方法。我认为这也适用于 getter/setter,因为它们只是特殊的方法(不过我自己还没有尝试过)。另见https://www.dartlang.org/articles/emulating-functions/#interactions-with-mirrors-and-nosuchmethod
该警告是因为你有没有实现它的接口,并且不类声明一个noSuchMethod方法。仅继承方法是不够的,您必须在类本身中实际声明它。
只需添加:
noSuchMethod(Invocation i) => super.noSuchMethod(i);
Run Code Online (Sandbox Code Playgroud)
这应该关闭该类的警告。
| 归档时间: |
|
| 查看次数: |
10874 次 |
| 最近记录: |