BodyExtra class

Use this annotation on a service method param when you want to add individual fields to the request body without defining a complete DTO class. This is useful when you need to include additional fields in the request body alongside existing data, or when you only need to send a few specific fields without creating a full data transfer object.

Unlike @Body which requires a complete DTO class to represent the entire request body, @BodyExtra allows you to define individual fields that will be merged into the final request body JSON. This provides more flexibility for scenarios where:

  • You need to add dynamic or conditional fields to an existing request
  • You want to avoid creating DTOs for simple field additions
  • You need to compose request bodies from multiple sources

Example:

@POST("/post")
Future<String> example(@Body UserDTO user, @BodyExtra("timestamp") int timestamp);

Results in: {"name": "John", "email": "[email protected]", "timestamp": 1234567890}

Constructors

BodyExtra.new(String value, {bool expand = false})
const

Properties

expand bool
Default is false. Controls how Object/Map values are handled:
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value String
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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