问题
What can I do to prevent the compiler from throwing the following warning
Missing concrete implementation of setter 'MyClass.field' and getter 'MyClass.field'
on the following code?
import 'package:mock/mock.dart';
class MyClass {
String field;
}
@proxy
class MockMyClass extends Mock implements MyClass{}
回答1:
Implement noSuchMethod();
When a class has a noSuchMethod()
it implements any method. I assume this applies to getter/setter as well because they are just special methods (never tried myself yet though). See also https://www.dartlang.org/articles/emulating-functions/#interactions-with-mirrors-and-nosuchmethod
回答2:
The warning comes because you have a class that doesn't implement its interface, and which doesn't declare a noSuchMethod
method.
It's not sufficient to inherit the method, you have to actually declare it in the class itself.
Just add:
noSuchMethod(Invocation i) => super.noSuchMethod(i);
That should turn off the warning for that class.
回答3:
About this warning ( Dart Spec ) :
** It is a static warning if a concrete class does not have an implementation for a method in any of its superinterfaces unless it declares its own noSuchMethod method (10.10). **
So you can create an implementation for getter field
in your MockMyClass
class.
来源:https://stackoverflow.com/questions/30274107/how-can-a-missing-concrete-implementation-warning-be-suppressed