ApiResponse class
The unified response object returned by every FlutterApiCraft.call.
Never throws — all errors are captured and surfaced through this object.
final res = await FlutterApiCraft(
baseUrl: 'https://api.example.com',
path: '/users',
).call();
if (res.isSuccess) {
print(res['data']); // read a key from the body Map
print(res.message); // read the "message" field
} else {
print(res.errorMessage); // human-readable error
print(res.statusCode); // HTTP status code (0 = network error)
}
Constructors
-
ApiResponse({required int statusCode, required String rawBody, required dynamic data, required bool isSuccess, required Map<
String, String> headers, String? errorMessage, Object? exception}) -
Creates an ApiResponse.
const
Properties
- data → dynamic
-
Parsed response body.
final
- errorMessage → String?
-
Human-readable error message extracted from the response body or the
caught exception.
final
- exception → Object?
-
Original exception object, when a Dart exception was caught instead of
receiving an HTTP response.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
→ Map<
String, String> -
All response headers as a flat key/value map.
final
- isNetworkError → bool
-
truewhen a network or Dart exception occurred (no HTTP response was received).no setter - isSuccess → bool
-
truewhen statusCode is 2xx anddata['success'](if present) istrue.final - message → String?
-
The
message(ormsg/detail) field from the response body, ornull.no setter - rawBody → String
-
Raw response body as a string.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- statusCode → int
-
HTTP status code.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
String key) → dynamic - Read a key directly from the response Map.