When exposing In-App Purchase (IAP) APIs, always prefer the generated handler typedefs and helper classes found in lib/types.dart. These types are synchronized with the OpenIAP schema, ensuring that parameter and return shapes remain consistent across the codebase. Using these generated signatures automatically handles nullability, optional flags, and platform-specific fields without requiring manual boilerplate.
final queryHandlers = QueryHandlers(
fetchProducts: ({required ProductRequest params}) async {
return _platform.fetchProducts(params: params);
},
);
final mutationHandlers = MutationHandlers(
finishTransaction: ({
required PurchaseInput purchase,
bool? isConsumable,
}) async {
return _platform.finishTransaction(
purchase: purchase,
isConsumable: isConsumable,
);
},
);