baseproject
This commit is contained in:
23
base_project/lib/data/response/api_response.dart
Normal file
23
base_project/lib/data/response/api_response.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:base_project/data/response/status.dart';
|
||||
|
||||
class ApiResponse<T> {
|
||||
Status? status;
|
||||
T? data;
|
||||
String? message;
|
||||
|
||||
ApiResponse(this.status, this.data, this.message);
|
||||
|
||||
// Named constructor for loading state
|
||||
ApiResponse.loading() : status = Status.LOADING;
|
||||
|
||||
// Named constructor for completed state
|
||||
ApiResponse.success(this.data) : status = Status.SUCCESS;
|
||||
|
||||
// Named constructor for error state
|
||||
ApiResponse.error(this.message) : status = Status.ERROR;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Status: $status \n Message: $message \n Data: $data";
|
||||
}
|
||||
}
|
||||
1
base_project/lib/data/response/status.dart
Normal file
1
base_project/lib/data/response/status.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum Status {LOADING,SUCCESS,ERROR}
|
||||
Reference in New Issue
Block a user