ClientResponse class

A unified response class that works with both http and dio backends.

Constructors

ClientResponse({required int statusCode, required String body, required List<int> bodyBytes, required Map<String, String> headers, required String requestUrl, required String method, int? requestDuration, bool isFromCache = false})
const

Properties

body String
The response body as a string.
final
bodyBytes List<int>
The response body as bytes.
final
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, String>
The response headers.
final
isClientError bool
Returns true if the status code indicates a client error (4xx).
no setter
isFromCache bool
Whether the request was from cache (if caching is enabled).
final
isRedirect bool
Returns true if the status code indicates a redirect (3xx).
no setter
isServerError bool
Returns true if the status code indicates a server error (5xx).
no setter
isSuccess bool
Returns true if the status code indicates success (2xx).
no setter
jsonBody Map<String, dynamic>?
Parses the response body as JSON and returns a Map.
no setter
jsonListBody List?
Parses the response body as a JSON list.
no setter
method String
The request method.
final
requestDuration int?
The time taken for the request in milliseconds.
final
requestUrl String
The request URL.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
statusCode int
The HTTP status code.
final

Methods

copyWith({int? statusCode, String? body, List<int>? bodyBytes, Map<String, String>? headers, String? requestUrl, String? method, int? requestDuration, bool? isFromCache}) ClientResponse
Creates a copy of this response with optional modifications.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseJson<T>(T fromJson(Map<String, dynamic> json)) → T?
Parses the response body as JSON and converts it using the provided function.
parseJsonList<T>(T fromJson(Map<String, dynamic> json)) List<T>?
Parses the response body as a JSON list and converts each item.
toString() String
A string representation of this object.
override

Operators

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