mergeHeaders static method
Merges multiple header maps into one.
Example:
final res = await client.post(
'/api/users',
headers: RequestHelper.mergeHeaders(
RequestHelper.jsonHeaders,
AuthHelper.bearer(token),
{'x-custom': 'value'},
),
body: jsonEncode({'name': 'John'}),
);
Implementation
static Map<String, String> mergeHeaders(
Map<String, String> first, [
Map<String, String>? second,
Map<String, String>? third,
Map<String, String>? fourth,
]) {
return {
...first,
if (second != null) ...second,
if (third != null) ...third,
if (fourth != null) ...fourth,
};
}