updateUserIcon method

Future<ThingSmartUserModel?> updateUserIcon({
  1. String? icon,
})

Updates the user icon with the provided icon.

Returns a Future that completes with a ThingSmartUserModel if the icon update is successful, or null if the update fails.

If the update is successful, the method also calls getUserInfo to retrieve the updated user information.

If an error occurs during the update, the error is logged using _log and null is returned.

The icon parameter is optional. If not provided, the user icon will not be updated.

Throws a PlatformException if there is an error during the method invocation.

Example usage:

ThingSmartUserModel? updatedUser = await updateUserIcon(icon: 'iconData');

Note: This method should be called after the user is logged in.

See also:

  • getUserInfo, which retrieves the user information after the icon update.
  • _log, which logs any errors that occur during the update.
  • PlatformException, which is thrown if there is an error during the method invocation.

Implementation

Future<ThingSmartUserModel?> updateUserIcon({
  String? icon,
}) async {
  try {
    var res = await methodChannel
        .invokeMethod('updateUserIcon', {'iconData': icon});
    if (res) {
      return getUserInfo();
    } else {
      return null;
    }
  } on PlatformException catch (e) {
    _log(e);
    return null;
  }
}