ApiResponse<T> class

Generic API Response Wrapper Provides structured response with generic type support

Constructors

ApiResponse({T? data, dynamic raw, required ResponseStatus status, ApiException? error, int? statusCode, Map<String, dynamic>? headers, String? message, Duration? duration})
ApiResponse.error({required ApiException error, dynamic raw, int? statusCode, Map<String, dynamic>? headers, Duration? duration})
Create error response
factory
ApiResponse.success({T? data, dynamic raw, int? statusCode, Map<String, dynamic>? headers, String? message, Duration? duration})
Create success response
factory

Properties

data → T?
Parsed data of generic type T
final
dataOrNull → T?
Get data or return null
no setter
dataOrThrow → T
Get data or throw error
no setter
duration Duration?
Request duration
final
error ApiException?
Error information (null if success)
final
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, dynamic>?
Response headers
final
isError bool
Check if response is error
no setter
isStatusSuccess bool
Check if status code is 2xx
no setter
isSuccess bool
Check if response is successful
no setter
message String?
Response message
final
raw → dynamic
Raw response data (JSON)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
status ResponseStatus
Response status (success/error)
final
statusCode int?
HTTP status code
final

Methods

copyWith({T? data, dynamic raw, ResponseStatus? status, ApiException? error, int? statusCode, Map<String, dynamic>? headers, String? message, Duration? duration}) ApiResponse<T>
Copy with new values
dataOrDefault(T defaultValue) → T
Get data or return default value
map<R>(R mapper(T data)) ApiResponse<R>
Map response to another type
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onError(void callback(ApiException error)) ApiResponse<T>
Execute callback on error
onSuccess(void callback(T? data)) ApiResponse<T>
Execute callback on success
toDetailedString() String
Get detailed string representation
toJson() Map<String, dynamic>
Convert to JSON
toString() String
Convert to string
override
transform<R>(R transformer(T? data)) ApiResponse<R>
Transform data to another type

Operators

operator ==(Object other) bool
The equality operator.
inherited