Last active
November 28, 2021 12:33
-
-
Save xsahil03x/0d31e3b2537cf93411f6d0f1b3f1d3b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
With null safety, it will be something like that:
class ApiResponse<T> {
Status status = Status.LOADING;
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 }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting this error
