createFlowView method
Future<AdaptyUIFlowView>
createFlowView({
- required AdaptyFlow flow,
- String? locale,
- String? customLayoutId,
- Duration? loadTimeout,
- bool preloadProducts = false,
- bool androidEnableSafeArea = true,
- Map<
String, String> ? customTags, - Map<
String, DateTime> ? customTimers, - Map<
String, AdaptyCustomAsset> ? customAssets, - Map<
AdaptyProductIdentifier, AdaptyPurchaseParameters> ? productPurchaseParams,
Right after receiving AdaptyFlow, you can create the corresponding AdaptyUIFlowView to present it afterwards.
Parameters
flow: an AdaptyFlow object, for which you are trying to get a controller.locale: the identifier of the localization to render the flow with, e.g.en,es,fr. If you don't pass it, the view is rendered inen, falling back to the flow's default localization when the flow has noen. Asking for a localization the flow does not have falls back to the flow default as well, without an error. Strings missing from the chosen localization are filled in from the default one.customLayoutId: the custom ID of a grid configured for this flow in the Adapty Flow Builder, to render instead of the grid selected automatically for the current device. Passnullto keep the automatic selection. The ID is matched exactly as given; an unknown ID fails with an AdaptyError.preloadProducts: If you passtrue,AdaptyUIwill automatically prefetch the required products at the moment of view assembly.androidEnableSafeArea: Android only. Iftrue, the flow view applies the safe-area insets as paddings. Has no effect on iOS. Defaults totrue.productPurchaseParams: A map that contains purchase parameters for specific products. The key is an AdaptyProductIdentifier and the value is AdaptyPurchaseParameters containing purchase-specific configuration.
Returns
- an AdaptyUIFlowView object, representing the requested flow screen.
Implementation
Future<AdaptyUIFlowView> createFlowView({
required AdaptyFlow flow,
String? locale,
String? customLayoutId,
Duration? loadTimeout,
bool preloadProducts = false,
bool androidEnableSafeArea = true,
Map<String, String>? customTags,
Map<String, DateTime>? customTimers,
Map<String, AdaptyCustomAsset>? customAssets,
Map<AdaptyProductIdentifier, AdaptyPurchaseParameters>? productPurchaseParams,
}) async {
// Encoded one by one, so an asset that cannot be sent fails with an AdaptyError naming it.
final encodedCustomAssets = customAssets?.entries.map((entry) {
try {
return {
Argument.id: entry.key,
...entry.value.jsonValue,
};
} catch (error) {
throw AdaptyError(
'Failed to encode custom asset "${entry.key}"',
AdaptyErrorCode.wrongParam,
error.toString(),
);
}
}).toList();
return Adapty()._invokeMethod<AdaptyUIFlowView>(
Method.createFlowView,
(data) {
final viewMap = data as Map<String, dynamic>;
return AdaptyUIFlowViewJSONBuilder.fromJsonValue(viewMap);
},
{
Argument.flow: flow.jsonValue,
if (locale != null) Argument.locale: locale,
if (customLayoutId != null) Argument.customLayoutId: customLayoutId,
Argument.preloadProducts: preloadProducts,
Argument.enableSafeAreaPaddings: androidEnableSafeArea,
if (loadTimeout != null) Argument.loadTimeout: loadTimeout.inMilliseconds.toDouble() / 1000.0,
if (customTags != null) Argument.customTags: customTags,
if (customTimers != null)
Argument.customTimers: customTimers.map((key, value) => MapEntry(
key,
value.toAdaptyValidString(),
)),
if (encodedCustomAssets != null) Argument.customAssets: encodedCustomAssets,
if (productPurchaseParams != null)
Argument.productPurchaseParameters: AdaptyProductIdentifier.convertProductPurchaseParamsToJson(
productPurchaseParams,
),
},
);
}