dart generic extends of Type issue.. method<T extends dynamic>

Viewed 874

I'm having a little problem here.. I'm trying to write a generic method of T type that extends from dynamic, but inside it show an error when I call an undefined method.

Code:

List<T> toListOf<T extends dynamic>(dynamic data, String key) {
  return List<T>.from(data[key]?.map((x) => T.fromMap(x)));
}

Image:

enter image description here

Error:

The method 'fromMap' isn't defined for the type 'Type'.

Try correcting the name to the name of an existing method, or defining a method named 'fromMap'

Any solutions?

0 Answers
Related