updateUser static method
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 optionalMBManager
used to make calls instead ofMBManager.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);
}