registerUser static method

Future<void> registerUser(
  1. String name,
  2. String surname,
  3. String email,
  4. String password, {
  5. String? phone,
  6. Uint8List? image,
  7. List<MBAuthContractAcceptanceParameter>? contracts,
  8. Map<String, dynamic>? data,
  9. MBManager? manager,
})

Registers a user to MBurger.

  • Parameters:
    • name: The name of the user.
    • surname: The surname of the user.
    • email: The email of the user.
    • password: The password 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 user is registered correctly.

Implementation

static Future<void> registerUser(
  String name,
  String surname,
  String email,
  String password, {
  String? phone,
  Uint8List? image,
  List<MBAuthContractAcceptanceParameter>? contracts,
  Map<String, dynamic>? data,
  MBManager? manager,
}) async {
  Map<String, String> parameters = {
    'name': name,
    'surname': surname,
    'email': email,
    'password': password,
  };

  if (phone != null) {
    parameters['phone'] = phone;
  }
  if (image != null) {
    parameters['image'] = base64.encode(image);
  }
  if (contracts != null) {
    List<Map<String, dynamic>> contractsArray =
        contracts.map((c) => c.representation).toList();
    parameters['contracts'] = json.encode(contractsArray);
  }
  if (data != null) {
    parameters['data'] = json.encode(data);
  }

  MBManager mbManager = manager ?? MBManager.shared;

  String apiName = 'api/register';

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

  Map<String, String> totalParameters = {};
  totalParameters.addAll(parameters);
  totalParameters.addAll(await mbManager.defaultParameters());

  var requestBody = json.encode(totalParameters);

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

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

  MBManager.checkResponse(response.body, checkBody: false);
}