How can a “missing concrete implementation” warning be suppressed?

て烟熏妆下的殇ゞ 提交于 2020-01-13 04:27:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!