I am trying to build a website using flutter but I can't figure out. 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'.
Any help is appreciated in advance.
CodePudding user response:
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:
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