updateUserDetails method

Future<bool> updateUserDetails(
  1. {String? name,
  2. DateTime? dob,
  3. String? orgCode}
)

Implementation

Future<bool> updateUserDetails({
  String? name,
  DateTime? dob,
  String? orgCode,
}) async {
  try {
    final Map<String, dynamic> userDetials = {};
    if (name != null) {
      userDetials["full_name"] = name;
    }
    if (dob != null) {
      userDetials["date_of_birth"] = dob.toString();
    }
    if (orgCode != null) {
      userDetials["organisation_code"] = orgCode;
    }
    Map response = await _apiService.putRequest(
      'v1/users/me',
      body: userDetials,
    );
    User u = User.fromJson(response['data']);
    currentUser!.setName(u.getName());
    currentUser!.setDateOfBirth(u.getDateOfBirth());
    print("new user og is ${u.organisation}");
    currentUser!.setOrganisation = u.organisation;
    return true;
  } catch (e) {
    return false;
  }
}