Process data from onboardings in Flutter SDK
Onboardings are deprecated in SDK v4 and will be removed in a future release. They no longer receive fixes or improvements. Use flows instead: unlike onboardings, which run inside a WebView, flows render natively on the device — giving you smoother animations, a consistent native look and feel, faster load times, and no WebView runtime dependency. See Get flows & paywalls and Display flows & paywalls to get started.
When your users respond to a quiz question or input their data into an input field, the onStateUpdatedAction method will be invoked. You can save or process the field type in your code.
For example:
// Full-screen presentation
void onboardingViewOnStateUpdatedAction(
AdaptyUIOnboardingView view,
AdaptyUIOnboardingMeta meta,
String elementId,
AdaptyOnboardingsStateUpdatedParams params,
) {
// Process data
}
// Embedded widget
onStateUpdatedAction: (meta, elementId, params) {
// Process data
}
See the action format here.
Property shapes for each params type (click to expand)
void onboardingViewOnStateUpdatedAction(
AdaptyUIOnboardingView view,
AdaptyUIOnboardingMeta meta,
String elementId,
AdaptyOnboardingsStateUpdatedParams params,
) {
// elementId is a String:
elementId; // 'preference_selector'
// meta — AdaptyUIOnboardingMeta:
meta.onboardingId; // 'onboarding_123'
meta.screenClientId; // 'preferences_screen'
meta.screenIndex; // 1
meta.screensTotal; // 3
// params is one of the AdaptyOnboardingsStateUpdatedParams subclasses:
switch (params) {
case AdaptyOnboardingsSelectParams(:final id, :final value, :final label):
// a single selected option
id; // 'option_1'
value; // 'premium'
label; // 'Premium Plan'
break;
case AdaptyOnboardingsMultiSelectParams(:final params):
// a list of selected options, each an AdaptyOnboardingsSelectParams
params; // [(id: 'interest_1', value: 'sports', label: 'Sports'), (id: 'interest_2', value: 'music', label: 'Music')]
break;
case AdaptyOnboardingsInputParams(:final input):
switch (input) {
case AdaptyOnboardingsTextInput(:final value):
value; // 'John Doe'
break;
case AdaptyOnboardingsEmailInput(:final value):
value; // 'user@example.com'
break;
case AdaptyOnboardingsNumberInput(:final value):
value; // 25.0 (a double)
break;
}
break;
case AdaptyOnboardingsDatePickerParams(:final day, :final month, :final year):
day; // 15
month; // 6
year; // 1990
break;
}
}Use cases
Enrich user profiles with data
If you want to immediately link the input data with the user profile and avoid asking them twice for the same info, you need to update the user profile with the input data when handling the action.
For example, you ask users to enter their name in the text field with the name ID, and you want to set this field’s value as user’s first name. Also, you ask them to enter their email in the email field. In your app code, it can look like this:
// Full-screen presentation
void onboardingViewOnStateUpdatedAction(
AdaptyUIOnboardingView view,
AdaptyUIOnboardingMeta meta,
String elementId,
AdaptyOnboardingsStateUpdatedParams params,
) {
// Store user preferences or responses
if (params is AdaptyOnboardingsInputParams) {
final builder = AdaptyProfileParametersBuilder();
// Map elementId to appropriate profile field
switch (elementId) {
case 'name':
if (params.input is AdaptyOnboardingsTextInput) {
builder.setFirstName((params.input as AdaptyOnboardingsTextInput).value);
}
break;
case 'email':
if (params.input is AdaptyOnboardingsEmailInput) {
builder.setEmail((params.input as AdaptyOnboardingsEmailInput).value);
}
break;
}
// Update profile
Adapty().updateProfile(builder.build()).catchError((error) {
// handle the error
});
}
}
// Embedded widget
onStateUpdatedAction: (meta, elementId, params) {
// Store user preferences or responses
if (params is AdaptyOnboardingsInputParams) {
final builder = AdaptyProfileParametersBuilder();
// Map elementId to appropriate profile field
switch (elementId) {
case 'name':
if (params.input is AdaptyOnboardingsTextInput) {
builder.setFirstName((params.input as AdaptyOnboardingsTextInput).value);
}
break;
case 'email':
if (params.input is AdaptyOnboardingsEmailInput) {
builder.setEmail((params.input as AdaptyOnboardingsEmailInput).value);
}
break;
}
// Update profile
Adapty().updateProfile(builder.build()).catchError((error) {
// handle the error
});
}
}
Customize paywalls based on answers
Using quizzes in onboardings, you can also customize paywalls you show users after they complete the onboarding.
For example, you can ask users about their experience with sport and show different CTAs and products to different user groups.
- Add a quiz in the onboarding builder and assign meaningful IDs to its options.
- Handle the quiz responses based on their IDs and set custom attributes for users.
// Full-screen presentation
void onboardingViewOnStateUpdatedAction(
AdaptyUIOnboardingView view,
AdaptyUIOnboardingMeta meta,
String elementId,
AdaptyOnboardingsStateUpdatedParams params,
) {
// Handle quiz responses and set custom attributes
if (params is AdaptyOnboardingsSelectParams) {
final builder = AdaptyProfileParametersBuilder();
// Map quiz responses to custom attributes
switch (elementId) {
case 'experience':
// Set custom attribute 'experience' with the selected value (beginner, amateur, pro)
builder.setCustomStringAttribute(params.value, 'experience');
break;
}
// Update profile
Adapty().updateProfile(builder.build()).catchError((error) {
// handle the error
});
}
}
// Embedded widget
onStateUpdatedAction: (meta, elementId, params) {
// Handle quiz responses and set custom attributes
if (params is AdaptyOnboardingsSelectParams) {
final builder = AdaptyProfileParametersBuilder();
// Map quiz responses to custom attributes
switch (elementId) {
case 'experience':
// Set custom attribute 'experience' with the selected value (beginner, amateur, pro)
builder.setCustomStringAttribute(params.value, 'experience');
break;
}
// Update profile
Adapty().updateProfile(builder.build()).catchError((error) {
// handle the error
});
}
}
- Create segments for each custom attribute value.
- Create a placement and add audiences for each segment you’ve created.
- Display a paywall for the placement in your app code. If your onboarding has a button that opens a paywall, implement the paywall code as a response to this button’s action.