solucx_widget 2.0.0
solucx_widget: ^2.0.0 copied to clipboard
SoluCXWidget is a Flutter widget that allows you to integrate SoluCX functionalities into your Flutter application.
SoluCXWidget #
The SoluCXWidget is a Flutter widget that allows integration with the SoluCX survey system. It offers different types of widgets that can be displayed in various positions on the screen, such as top, bottom, modal, or inline. The widget will automatically display without any trigger if a valid survey is configured.
Since 2.0.0, whether the widget can be shown at all is decided entirely by widget-api (sampling, display-interval rules, max attempts, etc.) — the SDK holds no local state about previous attempts or visits. See Availability check below.
Features #
- Support for different widget types:
bottom,top,modal,inline. - Control widget visibility.
- Survey height configured per journey (or set by the host app), falling back to the height the survey page reports.
- Server-side availability/blocking rules via
widget-api(sampling, display intervals, max attempts). - Integration with WebView for displaying web content.
- Automatic display without any trigger if a valid survey is configured.
Getting Started #
Prerequisites #
- Flutter SDK
- Project dependencies listed in
pubspec.yaml - Internet permission for Android and iOS
Installation #
Add SoluCXWidget to your Flutter project:
dependencies:
flutter:
sdk: flutter
solucx_widget: ^2.0.0
Configuration #
Android
Add the following permission to your AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yourapp">
<uses-permission android:name="android.permission.INTERNET"/>
<!-- ...existing code... -->
</manifest>
iOS
No extra setup is needed. Since 2.0.0 the survey is only loaded from https addresses, so there is no need to allow insecure connections in Info.plist. If you added NSAllowsArbitraryLoads for 1.x, you can remove it.
Usage #
Here is a basic example of how to use SoluCXWidget:
import 'package:flutter/material.dart';
import 'package:solucx_widget/solucx_widget.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('SoluCX Widget Example'),
),
body: Center(
child: SoluCXWidget(
soluCXKey: 'your-solucx-key',
type: SoluCXWidgetType.bottom,
data: SoluCXWidgetData(
journey: 'post-purchase',
clientId: 'client-id',
name: 'Client Name',
email: 'client@example.com',
),
options: SoluCXWidgetOptions(),
onBlocked: (reason) => print('Blocked by widget-api: $reason'),
onError: (message) => print('Availability check failed: $message'),
),
),
),
);
}
}
Interfaces #
SoluCXKey #
A type alias for String used as a unique identifier for the SoluCX widget.
SoluCXWidget #
A Flutter widget that integrates with the SoluCX survey system.
Properties
soluCXKey(required): ASoluCXKeythat uniquely identifies the widget.type(optional): ASoluCXWidgetTypethat specifies the type of widget (bottom, top, modal, inline). When omitted, the type configured server-side for the journey (widgetOptions.type) is used instead, falling back tobottom. An explicit localtypealways wins over the server's and is sent as an override in the availability check.data(required): ASoluCXWidgetDataobject containing the data to be sent to the survey.options(required): ASoluCXWidgetOptionsobject containing configuration options for the widget.alignment(optional): AnAlignmentobject specifying the alignment of the widget. Default isAlignment.center.webViewController(optional): AWebViewControllerfor controlling the WebView.timestampOverrides(optional): AWidgetTimestampOverrideswith pass-through overrides forwidget-api's time-based rules (see Availability check).onPreOpen(optional): Avoid Function(String? userId)called right before the widget becomes visible, oncewidget-apiconfirms the survey can open, receiving the identifier used for the blocking rules (clientId ?? cpf ?? email), if any.onOpened(optional): Avoid Function(String? userId)called when the widget becomes visible on screen, receiving the same identifier asonPreOpen.onBlocked(optional): Avoid Function(String? reason)called whenwidget-apiprevents the widget from opening, receiving the reason returned by the server (seeBlockReasonfor the known values — not a closed set).onClosed(optional): AVoidCallbackcalled when the widget is closed, either by the user or programmatically.onError(optional): Avoid Function(String message)called when the availability check fails (network error, timeout, malformed response), the survey page fails to load (connection, DNS or SSL error), or the survey page itself reports an error. In the last two cases the widget is also hidden, withoutonClosed.onCompleted(optional): Avoid Function(String? userId)called when the survey is fully completed by the user, receiving the same identifier asonPreOpen.onPartialCompleted(optional): Avoid Function(String? userId)called when the user submits the main rating (fires even if the survey is completed right after), receiving the same identifier asonPreOpen.onResize(optional): Avoid Function(String height)called when the survey page reports its height. It still fires when the height is fixed byoptions.heightor by the journey, but the widget then keeps the fixed height.
SoluCXWidgetType #
An enum representing the type of SoluCX widget.
bottom: Displays the widget at the bottom of the screen.top: Displays the widget at the top of the screen.modal: Displays the widget as a modal overlay.inline: Displays the widget inline within the existing layout.
SoluCXWidgetOptions #
Overrides for widget-api's server-side blocking rules, sent with every availability check. All rule fields are optional: when omitted, the server falls back to whatever is configured for the journey.
Properties
widgetWidth(optional): Adoublespecifying the width of the widget as a fraction of the display width. Default is1.0. Flutter-only — never sent towidget-api.enabled(optional): Aboolthat, whenfalse, blocks immediately withBLOCKED_BY_NOT_ENABLED.samplingPercentage(optional): Adouble(0-100) overriding the probability of the widget being shown, drawn on every availability check.height(optional): Adoublewith the survey height in logical pixels. Wins over the journey's configured height and over the height the survey page reports, as inwidget-rn.maxAttemptsAfterDismiss(optional): Anintoverriding how many times the survey can be shown for the same experience, identified bytransactionId. While the limit isn't reached, thewaitDaysAfterWidgetDisplayandwaitDaysAfterWidgetDismissintervals don't block; once it is, that experience is no longer shown (BLOCKED_BY_MAX_ATTEMPTS_EXCEEDED, or the interval's reason while one of those intervals is still running). Attempts are counted pertransactionId: without it the limit is never reached and those two intervals stop blocking.0turns the rule off.waitDaysAfterWidgetDisplayAttempt(optional): Anintoverriding the wait (in days) after a display attempt.waitDaysAfterWidgetFirstAccess(optional): Anintoverriding the wait (in days) after the customer's first access — combines withWidgetTimestampOverrides.lastFirstAccesswhen provided.waitDaysAfterWidgetDisplay(optional): Anintoverriding the wait (in days) after any display.waitDaysAfterWidgetDismiss(optional): Anintoverriding the wait (in days) after the widget is dismissed.waitDaysAfterWidgetSubmit(optional): Anintoverriding the wait (in days) after a full submission.waitDaysAfterWidgetPartialSubmit(optional): Anintoverriding the wait (in days) after a partial submission.
SoluCXWidgetData #
A class containing the data to be sent to the SoluCX survey.
Properties
transactionId(optional): AStringrepresenting the transaction ID.attemptId(optional): AStringrepresenting the attempt ID. Not sent towidget-apisince 2.0.0 (no server-side field).name(required for new customers): AStringrepresenting the name of the client. Required when SoluCX doesn't know the customer yet — without it the server can't register them and the survey doesn't open (onBlockedwithError creating Objects). Optional for customers SoluCX already knows.email(optional): AStringrepresenting the email of the client.clientId(optional): AStringrepresenting the client ID.cpf(optional): AStringrepresenting the CPF of the client. Sent towidget-apiasdocument.phone(optional): AStringrepresenting the phone number of the client.phone2(optional): AStringrepresenting the secondary phone number of the client.gender(optional): AStringrepresenting the gender of the client. Not sent towidget-apisince 2.0.0 (no server-side field).birthDate(optional): AStringrepresenting the birth date of the client.rating(optional): AStringrepresenting the rating given by the client. Sent towidget-apiasscore, only when numeric.storeId(optional): AStringrepresenting the store ID.employeeId(optional): AStringrepresenting the employee ID.amount(optional): Adoublerepresenting the amount of the transaction.journey(required since 2.0.0): AStringrepresenting the journey of the client. Must be sent together with a customer identifier (clientId,cpforemail) — without themwidget-apirejects the availability check,onErrorfires and the survey never opens.survey(optional): AStringindependent survey identifier, forwarded to the Survey Link as-is. Has no effect on the availability check today — it exists in preparation for a future journey migration (Jornadas V2) and does not replacejourney.
WidgetTimestampOverrides #
Pure pass-through overrides for widget-api's time-based blocking rules. The SDK never persists these itself — unlike previous versions' local quarantine model, the host app is responsible for storing each value and supplying the current one on every open (the same way widget-rn's overrideTimestamp works).
Properties
lastDisplayAttempt(optional): ADateTimeoverriding the last display-attempt timestamp (waitDaysAfterWidgetDisplayAttempt).lastFirstAccess(optional): ADateTimeoverriding the customer's first-access timestamp (waitDaysAfterWidgetFirstAccess). Without an override, the server falls back to the customer's registration date in the database.lastDisplay(optional): ADateTimeoverriding the last display timestamp (waitDaysAfterWidgetDisplay).lastDismiss(optional): ADateTimeoverriding the last dismiss timestamp (waitDaysAfterWidgetDismiss).lastSubmit(optional): ADateTimeoverriding the last full-submission timestamp (waitDaysAfterWidgetSubmit).lastPartialSubmit(optional): ADateTimeoverriding the last partial-submission timestamp (waitDaysAfterWidgetPartialSubmit).
Availability check #
Since 2.0.0, before showing anything, SoluCXWidget calls POST /widget/available on widget-api with soluCXKey, data, timestampOverrides and options. The response decides everything:
available: true+url→onPreOpen(userId)fires, the WebView loadsurl, the widget becomes visible,onOpened(userId)fires. The survey height followswidget-rn:options.heightset by the host app wins; then the journey's configured height (widgetOptions.height, which the server defaults to 600 px); without either, the height the page reports (onResize), and 300 px until it arrives.available: false+reason→onBlocked(reason)fires; the widget never opens.reasonis a plainString?, not a closed enum — seeBlockReasonfor the known values (BLOCKED_BY_NOT_ENABLED,BLOCKED_BY_SAMPLING, the sixBLOCKED_BY_WIDGET_*_INTERVALreasons,BLOCKED_BY_MAX_ATTEMPTS_EXCEEDED), but the server can also return an arbitrary downstream error message here (e.g.Error creating Objectsfor a new customer sent withoutname).- Missing
journey/customer identifier (rejected by the server), network failure, timeout, or a malformed/incomplete response (including a successful response missingurl, or a non-httpsurl) → fails closed:onError(message)fires, the widget never opens. This never crashes the host app.
There is no local fallback — a widget-api outage means the survey doesn't open, by design (see docs/adr.md).
Environment #
widget-api's base URL defaults to production and is overridable at build time via --dart-define=SOLUCX_WIDGET_API_BASE_URL=... (e.g. to point QA builds at a hmg/dev environment). Pair it with --dart-define=SOLUCX_SURVEY_EVENTS_ENDPOINT=... so telemetry from the same test run doesn't leak into production's pipeline.
Telemetry #
The widget sends its own lifecycle telemetry (widget opened, closed, completed, etc.) to SoluCX's survey-events endpoint, with the same event names as widget-rn (e.g. widget-closed for the SDK's close button) and the opening's context (data, userId, options merged with the journey's server-side options, timestampOverrides in epoch milliseconds) attached to every event, with values keeping their original types. That context includes the customer's personal data sent in data (name, email, CPF, etc.), as in widget-rn. This is independent from the on* callbacks above, which are for the host app; it can't be disabled by the host app itself, only server-side: clientSettings.disableEvents in the availability response suppresses specific events (by raw or widget--prefixed name) or all of them (*), and clientSettings.surveyEventsEndpoint overrides the endpoint.
Documentation #
For more information about the project, refer to the following documents in the docs/ directory:
- Troubleshooting Guide: A guide to common issues and their solutions.
- Architecture: Details about the service's architecture.
- Processes: Information about the internal processes of the service.
- API Documentation: Documentation of the API provided by the service.