Can I have a generic method in a injectable class?

Issue

Like:

@Injectable()
class ApiService {
  Future<T> fetch<T>(String path) {
    ...
  }
}

this doesn’t seem to work

Solution

It seems that it was fixed within the analyzer package 0.29:

https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/CHANGELOG.md

However, if you do:

T aa<T>() { 
  print(T.toString());
}

you will get a “dynamic” instead of the original class, which, very unfortunately, doesn’t help me

Answered By – Jonathan

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.