Professional Documents
Culture Documents
SK Request Maker - Dart
SK Request Maker - Dart
SK Request Maker - Dart
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:in_app_purchase/src/channel.dart';
import 'sk_product_wrapper.dart';
/// A request maker that handles all the requests made by SKRequest subclasses.
///
/// There are multiple [SKRequest](https://developer.apple.com/documentation/sto
rekit/skrequest?language=objc) subclasses handling different requests in the `St
oreKit` with multiple delegate methods,
/// we consolidated all the `SKRequest` subclasses into this class to make reque
sts in a more straightforward way.
/// The request maker will create a SKRequest object, immediately starting it, a
nd completing the future successfully or throw an exception depending on what ha
ppened to the request.
class SKRequestMaker {
/// Fetches product information for a list of given product identifiers.
///
/// The `productIdentifiers` should contain legitimate product identifiers tha
t you declared for the products in the iTunes Connect. Invalid identifiers
/// will be stored and returned in [SkProductResponseWrapper.invalidProductIde
ntifiers]. Duplicate values in `productIdentifiers` will be omitted.
/// If `productIdentifiers` is null, an `storekit_invalid_argument` error will
be returned. If `productIdentifiers` is empty, a [SkProductResponseWrapper]
/// will still be returned with [SkProductResponseWrapper.products] being null
.
///
/// [SkProductResponseWrapper] is returned if there is no error during the req
uest.
/// A [PlatformException] is thrown if the platform code making the request fa
ils.
Future<SkProductResponseWrapper> startProductRequest(
List<String> productIdentifiers) async {
final Map<String, dynamic> productResponseMap =
await channel.invokeMapMethod<String, dynamic>(
'-[InAppPurchasePlugin startProductRequest:result:]',
productIdentifiers,
);
if (productResponseMap == null) {
throw PlatformException(
code: 'storekit_no_response',
message: 'StoreKit: Failed to get response from platform.',
);
}
return SkProductResponseWrapper.fromJson(productResponseMap);
}