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): A SoluCXKey that uniquely identifies the widget.
  • type (optional): A SoluCXWidgetType that 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 to bottom. An explicit local type always wins over the server's and is sent as an override in the availability check.
  • data (required): A SoluCXWidgetData object containing the data to be sent to the survey.
  • options (required): A SoluCXWidgetOptions object containing configuration options for the widget.
  • alignment (optional): An Alignment object specifying the alignment of the widget. Default is Alignment.center.
  • webViewController (optional): A WebViewController for controlling the WebView.
  • timestampOverrides (optional): A WidgetTimestampOverrides with pass-through overrides for widget-api's time-based rules (see Availability check).
  • onPreOpen (optional): A void Function(String? userId) called right before the widget becomes visible, once widget-api confirms the survey can open, receiving the identifier used for the blocking rules (clientId ?? cpf ?? email), if any.
  • onOpened (optional): A void Function(String? userId) called when the widget becomes visible on screen, receiving the same identifier as onPreOpen.
  • onBlocked (optional): A void Function(String? reason) 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).
  • onClosed (optional): A VoidCallback called when the widget is closed, either by the user or programmatically.
  • onError (optional): A void 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, without onClosed.
  • onCompleted (optional): A void Function(String? userId) called when the survey is fully completed by the user, receiving the same identifier as onPreOpen.
  • onPartialCompleted (optional): A void Function(String? userId) called when the user submits the main rating (fires even if the survey is completed right after), receiving the same identifier as onPreOpen.
  • onResize (optional): A void Function(String height) called when the survey page reports its height. It still fires when the height is fixed by options.height or 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): A double specifying the width of the widget as a fraction of the display width. Default is 1.0. Flutter-only — never sent to widget-api.
  • enabled (optional): A bool that, when false, blocks immediately with BLOCKED_BY_NOT_ENABLED.
  • samplingPercentage (optional): A double (0-100) overriding the probability of the widget being shown, drawn on every availability check.
  • height (optional): A double with the survey height in logical pixels. Wins over the journey's configured height and over the height the survey page reports, as in widget-rn.
  • maxAttemptsAfterDismiss (optional): An int overriding how many times the survey can be shown for the same experience, identified by transactionId. While the limit isn't reached, the waitDaysAfterWidgetDisplay and waitDaysAfterWidgetDismiss intervals 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 per transactionId: without it the limit is never reached and those two intervals stop blocking. 0 turns the rule off.
  • waitDaysAfterWidgetDisplayAttempt (optional): An int overriding the wait (in days) after a display attempt.
  • waitDaysAfterWidgetFirstAccess (optional): An int overriding the wait (in days) after the customer's first access — combines with WidgetTimestampOverrides.lastFirstAccess when provided.
  • waitDaysAfterWidgetDisplay (optional): An int overriding the wait (in days) after any display.
  • waitDaysAfterWidgetDismiss (optional): An int overriding the wait (in days) after the widget is dismissed.
  • waitDaysAfterWidgetSubmit (optional): An int overriding the wait (in days) after a full submission.
  • waitDaysAfterWidgetPartialSubmit (optional): An int overriding the wait (in days) after a partial submission.

SoluCXWidgetData

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

Properties

  • transactionId (optional): A String representing the transaction ID.
  • attemptId (optional): A String representing the attempt ID. Not sent to widget-api since 2.0.0 (no server-side field).
  • name (required for new customers): A String representing 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 (onBlocked with Error creating Objects). Optional for customers SoluCX already knows.
  • email (optional): A String representing the email of the client.
  • clientId (optional): A String representing the client ID.
  • cpf (optional): A String representing the CPF of the client. Sent to widget-api as document.
  • phone (optional): A String representing the phone number of the client.
  • phone2 (optional): A String representing the secondary phone number of the client.
  • gender (optional): A String representing the gender of the client. Not sent to widget-api since 2.0.0 (no server-side field).
  • birthDate (optional): A String representing the birth date of the client.
  • rating (optional): A String representing the rating given by the client. Sent to widget-api as score, only when numeric.
  • storeId (optional): A String representing the store ID.
  • employeeId (optional): A String representing the employee ID.
  • amount (optional): A double representing the amount of the transaction.
  • journey (required since 2.0.0): A String representing the journey of the client. Must be sent together with a customer identifier (clientId, cpf or email) — without them widget-api rejects the availability check, onError fires and the survey never opens.
  • survey (optional): A String independent 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 replace journey.

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): A DateTime overriding the last display-attempt timestamp (waitDaysAfterWidgetDisplayAttempt).
  • lastFirstAccess (optional): A DateTime overriding 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): A DateTime overriding the last display timestamp (waitDaysAfterWidgetDisplay).
  • lastDismiss (optional): A DateTime overriding the last dismiss timestamp (waitDaysAfterWidgetDismiss).
  • lastSubmit (optional): A DateTime overriding the last full-submission timestamp (waitDaysAfterWidgetSubmit).
  • lastPartialSubmit (optional): A DateTime overriding 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 loads url, the widget becomes visible, onOpened(userId) fires. The survey height follows widget-rn: options.height set 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. reason is a plain String?, not a closed enum — see BlockReason for the known values (BLOCKED_BY_NOT_ENABLED, BLOCKED_BY_SAMPLING, the six BLOCKED_BY_WIDGET_*_INTERVAL reasons, BLOCKED_BY_MAX_ATTEMPTS_EXCEEDED), but the server can also return an arbitrary downstream error message here (e.g. Error creating Objects for a new customer sent without name).
  • Missing journey/customer identifier (rejected by the server), network failure, timeout, or a malformed/incomplete response (including a successful response missing url, or a non-https 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 (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:

Libraries

solucx_widget
SoluCX widget package.