Hi I'm trying to create generic API response class in flutter application and I'm getting this error
class ApiResponse<T> {
Status status;
T data;
String message;
ApiResponse.loading(this.message) : status = Status.LOADING;
ApiResponse.completed(this.data) : status = Status.COMPLETED;
ApiResponse.error(this.message) : status = Status.ERROR;
@override
String toString() {
return "Status : $status \n Message : $message \n Data : $data";
}
}
enum Status { LOADING, COMPLETED, ERROR }
IDE complains about below error
Non-nullable instance field 'data' must be initialized. Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'
Could anyone tell me what is wrong wiht my code?