richard
richard

Reputation: 3299

How can a "missing concrete implementation" warning be suppressed?

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{}

Upvotes: 5

Views: 13128

Answers (3)

lrn
lrn

Reputation: 71623

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.

Upvotes: 6

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657148

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

Upvotes: 6

GioLaq
GioLaq

Reputation: 2547

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.

Upvotes: 0

Related Questions