setUserId static method

Future<BaseResponse> setUserId(
  1. String userId
)

Modifies device user id. The default user id is set by device automatically.

It's an optional parameter that uniquely identifies your users within your application. You should set it only if you have a membership system for your app. You don't have to add it to PurchaseClient's constructor when creating an instance. Alternatively, you could specify your own user identifiers with PurchaseClient.instance.setUserId() later in your app lifecycle. This method requires a userId as a type of String and should be a unique value. It's necessary to fetch products and make purchase.

Device userId information.

Callbacks BaseResponse and GenericError in case of failure.

Implementation

static Future<BaseResponse> setUserId(String userId) async {
  List<Object?>? response =
      await _channel.invokeMethod('setUserId', {"userId": userId});
  BaseResponse result = new BaseResponse(false, null);
  if (response != null) {
    if (response[0] != null) {
      result = new BaseResponse(response[0].toString() == "true", null);
    }
    if (response[1] != null) {
      GenericError error =
          GenericError.fromJson(json.decode(response[1]!.toString()));
      result = new BaseResponse(false, error);
    }
    return result;
  }
  return result;
}