I am very new to Dart and Flutter, and I've been trying to make two classes (SuccessState and ErrorState) that implement an abstract class (DataState) with optional named parameters. For some reason, whenever I call the super constructor in SuccessState and ErrorState, I get an undefined_named_parameter error on the "data" parameter in the SuccessState constructor and "status" and "msg" parameters in the ErrorState constructor. Any input is greatly appreciated, thanks.
abstract class DataState<T> {
final T? data;
final int? status;
final String? msg;
const DataState({this.data, this.status, this.msg});
}
class SuccessState<T> implements DataState<T> {
const SuccessState(T data) : super(data: data);
@override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
class ErrorState<T> implements DataState<T> {
const ErrorState(int status, String msg) : super(status: status, msg: msg);
@override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
You want to extend SuccessState and ErrorState to DataState.
abstract class DataState<T> {
final T? data;
final int? status;
final String? msg;
const DataState({this.data, this.status, this.msg});
}
class SuccessState<T> extends DataState<T> {
SuccessState(T data) : super(data: data);
@override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
class ErrorState<T> implements DataState<T> {
const ErrorState(int status, String msg) : super();
@override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}