Flutter

PUB.DEV Repository

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.

Since version 2.0.0, whether the widget can be shown at all is decided entirely by widget-api (sampling, interval rules, max attempts, etc.) — the SDK no longer holds any local state about previous attempts or visits. See Availability check below.

Features

  • Support for different widget types: bottom, top, modal, inline.
  • Widget visibility control.
  • Survey height configured per journey (or set by the app), falling back to the height the page reports.
  • Server-side blocking/availability rules via widget-api (sampling, intervals, max attempts).
  • WebView integration to display web content.
  • Lifecycle callbacks (onPreOpen, onOpened, onBlocked, onClosed, onError, onCompleted, onPartialCompleted, onResize) for observability and analytics integration.

Getting started

Prerequisites

  • Flutter SDK
  • Project dependencies listed in pubspec.yaml
  • Internet permission on Android and iOS

Installation

Add SoluCXWidget to your Flutter project:

dependencies:
    flutter:
        sdk: flutter
    solucx_widget: ^2.0.0

Setup

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',
            data: SoluCXWidgetData(
              journey: 'post-purchase',
              clientId: 'customer-id',
              name: 'Customer Name',
              email: '[email protected]',
            ),
            options: SoluCXWidgetOptions(),
            onBlocked: (reason) => print('Blocked by widget-api: $reason'),
            onError: (message) => print('Availability check failed: $message'),
          ),
        ),
      ),
    );
  }
}

Migrating from 1.x

Version 2.0.0 brings breaking changes from 1.x:

  • journey and a customer identifier (clientId, cpf or email) are now required. Without them, onError fires and the survey never opens.
  • The retryAttempts, retryInterval, collectInterval and collectPartialInterval options were replaced by the SoluCXWidgetOptions rules. When omitted, the journey configuration applies.
  • The SDK no longer stores attempts and displays on the device, and SoluCXWidgetService/StorageRepository were removed. To provide that history, use WidgetTimestampOverrides.
  • onBlocked now receives the block reason (reason), and there are new callbacks: onPreOpen, onError and onResize.
  • cpf is sent as document and rating as score (only when numeric); attemptId and gender are no longer sent.
  • The widget usage events sent to SoluCX can be turned off by SoluCX, with no change to the app.

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

SoluCXWidget parameters

Main properties to configure the widget.
soluCXKeySoluCXKey
Unique identifier of the SoluCX widget (required).
typeSoluCXWidgetType|null
Widget type: bottom, top, modal or inline (optional). When omitted, the type configured server-side for the journey is used (widgetOptions.type), falling back to bottom. An explicit local type always takes priority over the server's.
dataSoluCXWidgetData
Data sent to the survey (required).
optionsSoluCXWidgetOptions
Additional configuration options for the widget (required).
alignmentAlignment|null
Widget alignment. Default: Alignment.center (optional).
webViewControllerWebViewController|null
WebView controller (optional).
timestampOverridesWidgetTimestampOverrides|null
Pure pass-through overrides for widget-api's time-based rules (optional). See Availability check.
onPreOpenvoid Function(String? userId)|null
Called right before the widget becomes visible, once widget-api confirms the survey can open, receiving the identifier used in the rules (clientId ?? cpf ?? email; the CPF is sent to widget-api as document), if any (optional).
onOpenedvoid Function(String? userId)|null
Called when the widget becomes visible on screen, receiving the same identifier as onPreOpen (optional).
onBlockedvoid Function(String? reason)|null
Called when widget-api prevents the widget from opening, receiving the reason returned by the server (see BlockReason for the known values — not a closed set) (optional).
onClosedVoidCallback|null
Called when the widget is closed, either by the user or programmatically (optional).
onErrorvoid Function(String message)|null
Called when the availability check fails (network error, timeout, malformed response), the survey page fails to load in the WebView (connection, DNS or SSL error), or the survey itself reports an error (optional). In the last two cases the widget is also hidden, without onClosed.
onCompletedvoid Function(String? userId)|null
Called when the survey is fully completed by the user, receiving the same identifier as onPreOpen (optional).
onPartialCompletedvoid Function(String? userId)|null
Called when the user submits the main rating (NPS/CSAT/CES), regardless of whether the remaining survey steps are later completed; receives the same identifier as onPreOpen (optional).
onResizevoid Function(String height)|null
Called when the survey page reports its height (optional). It still fires when the height is fixed (options.height or the journey's), but the widget then keeps the fixed height.

Callbacks

Functions called at each step of the widget's lifecycle. All of them are optional. onPreOpen, onOpened, onCompleted and onPartialCompleted receive the identifier (String?) used for the blocking rules (clientId ?? cpf ?? email; the CPF is sent to widget-api as document), when any.

SoluCXWidget(
  soluCXKey: 'your-solucx-key',
  data: SoluCXWidgetData(
    journey: 'post-purchase',
    clientId: 'customer-id',
    name: 'Customer Name',
    email: '[email protected]',
  ),
  options: SoluCXWidgetOptions(),
  onPreOpen: (userId) => print('Preparing widget for $userId'),
  onOpened: (userId) => print('Widget displayed for $userId'),
  onBlocked: (reason) => print('Blocked: $reason'),
  onClosed: () => print('Widget closed'),
  onError: (message) => print('Error: $message'),
  onCompleted: (userId) => print('Survey completed by $userId'),
  onPartialCompleted: (userId) => print('Main rating submitted by $userId'),
  onResize: (height) => print('New height: $height'),
)
CallbackParameterWhen it is called
onPreOpenuserId: String?Before the widget becomes visible, once widget-api allows the display
onOpeneduserId: String?When the widget becomes visible on screen
onBlockedreason: String?When widget-api prevents the display. See BlockReason
onClosed-When the widget is closed, by the user or programmatically
onErrormessage: StringWhen the availability check fails, or the survey reports an error
onCompleteduserId: String?When the user completes the full survey
onPartialCompleteduserId: String?When the user submits the main rating (NPS/CSAT/CES) — fires even if the survey is completed right after
onResizeheight: StringWhen the survey page reports its height

BlockReason

Known reasons widget-api may return when it prevents the widget from opening. Not a closed set: on a downstream failure the server can also return an arbitrary error message in reason.

class BlockReason {
  static const String notEnabled = 'BLOCKED_BY_NOT_ENABLED';
  static const String sampling = 'BLOCKED_BY_SAMPLING';
  static const String displayAttemptInterval = 'BLOCKED_BY_WIDGET_DISPLAY_ATTEMPT_INTERVAL';
  static const String firstAccessInterval = 'BLOCKED_BY_WIDGET_FIRST_ACCESS_INTERVAL';
  static const String displayInterval = 'BLOCKED_BY_WIDGET_DISPLAY_INTERVAL';
  static const String dismissInterval = 'BLOCKED_BY_WIDGET_DISMISS_INTERVAL';
  static const String submitInterval = 'BLOCKED_BY_WIDGET_SUBMIT_INTERVAL';
  static const String partialSubmitInterval = 'BLOCKED_BY_WIDGET_PARTIAL_SUBMIT_INTERVAL';
  static const String maxAttemptsExceeded = 'BLOCKED_BY_MAX_ATTEMPTS_EXCEEDED';
}
ReasonDescription
BLOCKED_BY_NOT_ENABLEDWidget disabled (enabled: false)
BLOCKED_BY_SAMPLINGDisplay not drawn by sampling (samplingPercentage)
BLOCKED_BY_WIDGET_DISPLAY_ATTEMPT_INTERVALWithin the interval after a display attempt
BLOCKED_BY_WIDGET_FIRST_ACCESS_INTERVALWithin the interval after the customer's first access
BLOCKED_BY_WIDGET_DISPLAY_INTERVALWithin the interval after a display
BLOCKED_BY_WIDGET_DISMISS_INTERVALWithin the interval after the widget is dismissed
BLOCKED_BY_WIDGET_SUBMIT_INTERVALWithin the interval after a full submission
BLOCKED_BY_WIDGET_PARTIAL_SUBMIT_INTERVALWithin the interval after a partial submission
BLOCKED_BY_MAX_ATTEMPTS_EXCEEDEDMaximum number of display attempts reached

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 uses whatever is configured for the journey.

options parameter

Additional configuration options for the widget.
widgetWidthdouble
Widget width as a fraction of the screen width (0.0 to 1.0). Default value: 1.0. Flutter-only — never sent to widget-api.
enabledbool|null
When false, blocks immediately with BLOCKED_BY_NOT_ENABLED.
samplingPercentagedouble|null
Probability (0-100) of the widget being shown, drawn on every availability check.
heightdouble|null
Survey height in logical pixels. Wins over the journey's configured height and over the height the page reports, as in React Native.
maxAttemptsAfterDismissint|null
How many times the survey can be shown for the same experience, identified by transactionId. While this limit isn't reached, the waitDaysAfterWidgetDisplay and waitDaysAfterWidgetDismiss intervals don't block; once it is reached, that experience is no longer shown (reason BLOCKED_BY_MAX_ATTEMPTS_EXCEEDED, or the interval's reason while one of those intervals is still running). Attempts are counted per transactionId: without it, the limit is never reached and those two intervals stop blocking. 0 turns the rule off.
waitDaysAfterWidgetDisplayAttemptint|null
Wait (in days) after a display attempt.
waitDaysAfterWidgetFirstAccessint|null
Wait (in days) after the customer's first access, combined with WidgetTimestampOverrides.lastFirstAccess when provided.
waitDaysAfterWidgetDisplayint|null
Wait (in days) after any display.
waitDaysAfterWidgetDismissint|null
Wait (in days) after the widget is dismissed.
waitDaysAfterWidgetSubmitint|null
Wait (in days) after a full submission.
waitDaysAfterWidgetPartialSubmitint|null
Wait (in days) after a partial submission.

WidgetTimestampOverrides

Pure pass-through overrides for widget-api's time-based rules. The SDK never persists these values — unlike previous versions' local quarantine model, the host app is responsible for storing each value and supplying the current one on every open.

timestampOverrides parameter

Optional timestamp overrides.
lastDisplayAttemptDateTime|null
Overrides the last display-attempt timestamp (waitDaysAfterWidgetDisplayAttempt).
lastFirstAccessDateTime|null
Overrides the customer's first-access timestamp (waitDaysAfterWidgetFirstAccess). Without the override, the server falls back to the customer's real registration date.
lastDisplayDateTime|null
Overrides the last display timestamp (waitDaysAfterWidgetDisplay).
lastDismissDateTime|null
Overrides the last dismiss timestamp (waitDaysAfterWidgetDismiss).
lastSubmitDateTime|null
Overrides the last full-submission timestamp (waitDaysAfterWidgetSubmit).
lastPartialSubmitDateTime|null
Overrides the last partial-submission timestamp (waitDaysAfterWidgetPartialSubmit).

Availability check

Since version 2.0.0, before displaying anything, SoluCXWidget calls POST /widget/available on widget-api with soluCXKey, data, timestampOverrides, options, and, when an explicit local type is provided, also type. The response decides everything:

  • available: true + url → onPreOpen(userId) fires, the WebView loads url, the widget becomes visible, onOpened(userId) fires. The survey height is the one set by the app in options.height; without it, the one configured for the journey (600 px by default), which takes priority over the height the page reports; without either, the page's height is used, and 300 px until it arrives.
  • available: false + reason → onBlocked(reason) fires; the widget never opens. reason is a plain String?, not a closed enum — see BlockReason for the known values, but the server can also return an arbitrary error message.
  • Network failure, timeout, or a malformed/incomplete response (including a successful response missing url) → 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.

SoluCXWidgetData

A class containing the data to be sent to the SoluCX survey.

Properties

data parameter

Data sent to the SoluCX survey.
transactionIdString|null
Transaction ID (optional).
attemptIdString|null
Attempt ID (optional). Not sent to widget-api since 2.0.0.
nameString|null
Customer name. Required for customers SoluCX does not know yet: without it the customer is not registered and the survey does not open (onBlocked with Error creating Objects). Optional for customers SoluCX already knows.
emailString|null
Customer email (optional).
clientIdString|null
Customer ID (optional).
cpfString|null
Customer CPF (optional). Sent to widget-api as document.
phoneString|null
Customer phone number (optional).
phone2String|null
Customer secondary phone number (optional).
genderString|null
Customer gender (optional). Not sent to widget-api since 2.0.0.
birthDateString|null
Customer birth date (optional).
ratingString|null
Rating given by the customer (optional). Sent to widget-api as score, only when numeric.
storeIdString|null
Store ID (optional).
employeeIdString|null
Employee ID (optional).
amountdouble|null
Transaction amount (optional).
journeyString|null
Customer journey. Required since 2.0.0, alongside a customer identifier (clientId, cpf or email): without them widget-api rejects the availability check, onError fires and the survey never opens.
surveyString|null
Independent survey identifier, forwarded to the Survey Link as-is. Currently optional and has no effect on blocking rules — it exists in preparation for a future journey migration (Jornadas V2) and doesn't yet substitute for journey for that purpose.