headers method
Default headers sent to MBurger.
- Parameters:
contentTypeJson
: iftrue
it adds this headerContent-Type: application/json
.
- Returns a Future that completes with the map of default headers.
Implementation
Future<Map<String, String>> headers({bool contentTypeJson = false}) async {
Map<String, String> headers = {
'Accept': 'application/json',
'X-MBurger-Version': '3',
};
if (apiToken != null) {
headers['X-MBurger-Token'] = apiToken!;
}
bool userLoggedIn = await MBAuth.userLoggedIn();
if (userLoggedIn == true) {
String? token = await MBAuth.userToken();
if (token != null) {
headers['Authorization'] = 'Bearer $token';
}
}
if (contentTypeJson) {
headers['Content-Type'] = 'application/json';
}
return headers;
}