headers method

Future<Map<String, String>> headers({
  1. bool contentTypeJson = false,
})

Default headers sent to MBurger.

  • Parameters:
    • contentTypeJson: if true it adds this header Content-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;
}