简体   繁体   English

将抽象类的扩展类作为参数传递给 flutter

[英]Pass extended class of an abstract class as a parameter in flutter

I am trying to build a website using flutter but I can't figure out.我正在尝试使用 flutter 构建一个网站,但我无法弄清楚。 This is an abstract class.这是一个抽象类。

abstract class TableBaseClass {
  int getPage(BuildContext context);
  void setPage(int val,BuildContext context);
  int getPagination();
  void setPagination(String val,BuildContext context);
  void setSearch(String val,BuildContext context);
  String getSearch();
  dynamic getData();
  List getHeaders();
  List getBodyFields();
  void refresh(BuildContext context);
  void setSort(String header);
  void setOrder(String order,BuildContext context);
  String getOrder();
}

And this class is extending it.这个类正在扩展它。

class Objects extends TableBaseClass with ChangeNotifier {

and this widget takes the abstract class as a parameter.这个小部件将抽象类作为参数。

class TableWidget extends StatefulWidget {
  final TableBaseClass provider;
  final String menuButton;

  const TableWidget(this.provider,this.menuButton, {super.key});

but when I pass the Objects class TableWidget(Objects,menuButton) It gives error The argument type 'Type' can't be assigned to the parameter type 'TableBaseClass'.但是当我传递对象类TableWidget(Objects,menuButton)时,它给出了错误The argument type 'Type' can't be assigned to the parameter type 'TableBaseClass'.

Any help is appreciated in advance.提前感谢任何帮助。

because you're simply trying to pass a Type, not an instance of the TableBaseClass class, you didn't call the class constructor, see this:因为您只是想传递一个类型,而不是TableBaseClass类的实例,所以您没有调用类构造函数,请参见:

print(TableBaseClass); // this is a type, 
print(TableBaseClass.runtimeType); // Type

but with () , you're creating an instance of that class:但是使用() ,您正在创建该类的一个实例:

print(TableBaseClass()); // this is an instance of TableBaseClass 
print(TableBaseClass().runtimeType); // TableBaseClass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM