Function 类型为issue.的dart泛型扩展。。方法<;T扩展动态>;

Function 类型为issue.的dart泛型扩展。。方法<;T扩展动态>;,function,generics,dart,types,Function,Generics,Dart,Types,我这里有点小问题。。我试图编写一个T类型的泛型方法,该方法从dynamic扩展而来,但是当我调用一个未定义的方法时,它内部显示了一个错误 代码: 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' List toListOf(动态数据,字符串键

我这里有点小问题。。我试图编写一个T类型的泛型方法,该方法从dynamic扩展而来,但是当我调用一个未定义的方法时,它内部显示了一个错误

代码

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'
List toListOf(动态数据,字符串键){
返回列表.from(数据[键]?.map((x)=>T.fromMap(x));
}
图像

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'

错误

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'

有什么解决方案吗?

@Christophermore好吧,我有4个模型类,每个都有fromMap,但如果我只是从其中一个扩展,那就没有意义了!!这是正确的。如果每个模型都有一个fromMap方法,那么创建一个抽象类并使您的模型扩展该类。然后在函数中使用抽象类作为类型。
。fromMap
不是实例方法;它是一个构造函数(或静态方法)。你不能笼统地使用它们。相反,您可以让
toListOf
接受一个调用相应
.fromMap
构造函数的回调。@jamesdlin确切地说,fromMap不是一个方法。。它是一个工厂构造函数,不能只做一个抽象类,然后扩展它,我会尝试你上面建议的。。非常感谢。