updateUser static method

Future<MBUser> updateUser({
  1. String? name,
  2. String? surname,
  3. String? phone,
  4. Uint8List? image,
  5. Map<String, dynamic>? data,
  6. List<MBAuthContractAcceptanceParameter>? contracts,
  7. MBManager? manager,
})

Updates user information, only data that are passed to this function are changed, the fields not passed will remain untouched.

  • Parameters:
    • name: The name of the user.
    • surname: The surname of the user.
    • phone: An optional telephone number.
    • image: An optional profile image.
    • contracts: If there are contracts in the project the user can accept/decline them and you can tell this to MBurger with this parameter.
    • data: Optional additional data.
    • manager: An optional MBManager used to make calls instead of MBManager.shared.
  • Returns a Future that completes when the profile is changed correctly.

Implementation

static Future<MBUser> updateUser({
  String? name,
  String? surname,
  String? phone,
  Uint8List? image,
  Map<String, dynamic>? data,
  List<MBAuthContractAcceptanceParameter>? contracts,
  MBManager? manager,
}) async {
  MBManager mbManager = manager ?? MBManager.shared;

  String apiName = 'api/profile/update';

  Map<String, String> apiParameters = await mbManager.defaultParameters();
  if (name != null) {
    apiParameters['name'] = name;
  }
  if (surname != null) {
    apiParameters['surname'] = surname;
  }
  if (phone != null) {
    apiParameters['phone'] = phone;
  }
  if (image != null) {
    apiParameters['image'] = base64.encode(image);
  }
  if (data != null) {
    apiParameters['data'] = jsonEncode(data);
  }
  if (contracts != null) {
    apiParameters['contracts'] =
        jsonEncode(contracts.map((c) => c.representation).toList());
  }

  var uri = Uri.https(mbManager.endpoint, apiName);

  Map<String, String> headers =
      await mbManager.headers(contentTypeJson: true);

  String requestBody = jsonEncode(apiParameters);

  http.Response response = await http.post(
    uri,
    headers: headers,
    body: requestBody,
  );

  Map<String, dynamic> body = MBManager.checkResponse(response.body);
  return MBUser.fromDictionary(body);
}