【发布时间】:2020-05-12 11:04:34
【问题描述】:
所以有这样一个类
class Base<T extends BaseClass> extends StatefulWidget
并且我想使用该类而不直接提供扩展 BaseClass 的对象,而是通过构造函数传递一些东西。
class Something extends StatelessWidget {
final /*what type I am supposed to give here*/ test;
const Something({Key key, this.test}) : super(key: key);
@override
Widget build(BuildContext context) {
return Base<test>();
}
}
我得到的错误警告是
'dynamic' doesn't extend 'BaseClass'.
Try using a type that is or is a subclass of 'BaseClass'.dart(type_argument_not_matching_bounds)
The name 'test' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named 'test'.dart(non_type_as_type_argument)
【问题讨论】: