Surveys
Surveys in the Flutter SDK.
import 'package:nexus_flutter/nexus.dart';| Symbol | Kind | Summary |
|---|---|---|
NexusSurveys | class | In-product surveys. |
NexusSurveyChoice | class | |
NexusSurveyQuestion | class | |
NexusSurveyTrigger | class | |
NexusSurvey | class | |
SurveySubmit | typedef | Persists a response (partial or terminal). |
NexusSurveyController | class | Drives one survey: holds answers, step position, validity, and submit/dismiss. |
NexusQuestionBuilder | typedef | Override the rendering of a single question. |
NexusSurveyView | class | The built-in survey card. |
NexusSurveyBuilder | typedef | Fully replace the survey UI. |
NexusSurveyOverlay | class | Hosts the currently-active survey above your app. |
NexusSurveys
classIn-product surveys. Fetches the surveys a user is eligible for, decides which
to show (auto-show for popover/banner types + event triggers), and submits
answers. The rendering is done by NexusSurveyOverlay (default UI) or your
own widget driven by NexusSurveyController.
active
propertyList<NexusSurvey> get activeAll surveys the user is currently eligible for.
View sourcecurrent
fieldfinal ValueNotifier<NexusSurvey?> currentThe survey currently requested to display (null when none). The overlay listens to this.
View sourcefetch()
methodFuture<List<NexusSurvey>> fetch()Fetch eligible surveys from the server (targeting/sampling/capping applied).
Returns Future<List<NexusSurvey>>
onEvent()
methodvoid onEvent(String name)Called when an analytics event fires — shows a survey gated on that event.
Parameters
Prop
Type
show()
methodvoid show(NexusSurvey survey)Present a specific survey now (e.g. from a "Give feedback" button).
Parameters
Prop
Type
close()
methodvoid close()Remove the current survey from the screen (called by the UI when done).
View sourcebyId()
methodNexusSurvey? byId(String id)Parameters
Prop
Type
Returns NexusSurvey?
respond()
methodFuture<void> respond(NexusSurvey survey, Map<String, Object?> answers, {bool completed = false, bool dismissed = false})Submit a response (partial, complete, or dismissed). Best-effort.
Parameters
Prop
Type
dispose()
methodvoid dispose()NexusSurveyChoice
class View sourceNexusSurveyChoice
constructorconst NexusSurveyChoice({required this.value, this.label, this.open = false})Parameters
Prop
Type
fromJson()
static methodstatic NexusSurveyChoice fromJson(dynamic json)Parameters
Prop
Type
Returns NexusSurveyChoice
display
propertyString get displayvalue
fieldfinal String valuelabel
fieldfinal String? labelopen
fieldfinal bool openNexusSurveyQuestion
class View sourceNexusSurveyQuestion
constructorconst NexusSurveyQuestion({required this.id, required this.type, required this.label, this.description, this.required = false, this.choices = const [], this.display, this.scaleMin, this.scaleMax, this.lowerLabel, this.upperLabel, this.buttonText, this.buttonUrl})Parameters
Prop
Type
fromJson()
static methodstatic NexusSurveyQuestion fromJson(Map<String, dynamic> m)Parameters
Prop
Type
Returns NexusSurveyQuestion
isMultiSelect
propertybool get isMultiSelecttype
fieldfinal String typeopen | single_choice | multiple_choice | rating | nps | boolean | link | email
View sourceid
fieldfinal String idlabel
fieldfinal String labeldescription
fieldfinal String? descriptionrequired
fieldfinal bool requiredchoices
fieldfinal List<NexusSurveyChoice> choicesdisplay
fieldfinal String? displayscaleMin
fieldfinal int? scaleMinscaleMax
fieldfinal int? scaleMaxlowerLabel
fieldfinal String? lowerLabelupperLabel
fieldfinal String? upperLabelbuttonText
fieldfinal String? buttonTextbuttonUrl
fieldfinal String? buttonUrlNexusSurveyTrigger
class View sourceNexusSurveyTrigger
constructorconst NexusSurveyTrigger({this.events = const [], this.delaySeconds, this.minInterval, this.selector})Parameters
Prop
Type
fromJson()
static methodstatic NexusSurveyTrigger? fromJson(Map<String, dynamic>? m)Parameters
Prop
Type
Returns NexusSurveyTrigger?
events
fieldfinal List<String> eventsdelaySeconds
fieldfinal int? delaySecondsminInterval
fieldfinal int? minIntervalselector
fieldfinal String? selectorNexusSurvey
class View sourceNexusSurvey
constructorconst NexusSurvey({required this.id, required this.name, required this.type, required this.questions, this.appearance = const {}, this.trigger, this.iterationKey, this.resumeResponseId, this.resumeAnswers = const {}})Parameters
Prop
Type
fromJson()
static methodstatic NexusSurvey fromJson(dynamic json)Parameters
Prop
Type
Returns NexusSurvey
position
propertyString? get positionprimaryColorHex
propertyString? get primaryColorHexthankYouTitle
propertyString? get thankYouTitlethankYouMessage
propertyString get thankYouMessageshowThankYou
propertybool get showThankYoushowProgressBar
propertybool get showProgressBarsubmitButtonText
propertyString? get submitButtonTextid
fieldfinal String idname
fieldfinal String nametype
fieldfinal String typequestions
fieldfinal List<NexusSurveyQuestion> questionsappearance
fieldfinal Map<String, Object?> appearancetrigger
fieldfinal NexusSurveyTrigger? triggeriterationKey
fieldfinal String? iterationKeyresumeResponseId
fieldfinal String? resumeResponseIdresumeAnswers
fieldfinal Map<String, Object?> resumeAnswersSurveySubmit
typedeftypedef SurveySubmit = Future<void> Function(NexusSurvey survey, Map<String, Object?> answers, {bool completed, bool dismissed})Persists a response (partial or terminal). Wired to the surveys service.
View sourceNexusSurveyController
classclass NexusSurveyController extends ChangeNotifierDrives one survey: holds answers, step position, validity, and submit/dismiss.
This is the seam for custom UIs — pass your own widget to the overlay and
drive it entirely from this controller (currentQuestion, setAnswer,
next, back, complete, dismiss, progress). It's a ChangeNotifier,
so rebuild on changes.
step
propertyint get steptotalSteps
propertyint get totalStepsisDone
propertybool get isDoneisSubmitting
propertybool get isSubmittingprogress
propertydouble get progressisLast
propertybool get isLastcurrentQuestion
propertyNexusSurveyQuestion? get currentQuestioncanAdvance
propertybool get canAdvanceWhether the current (required) question has a valid answer.
View sourcesurvey
fieldfinal NexusSurvey surveyonClose
fieldVoidCallback? onCloseWired by the overlay to remove the survey from the screen. Call close
from your UI when you're done presenting (e.g. after a thank-you).
answers
fieldfinal Map<String, Object?> answersAnswers keyed by question id (value type depends on question type).
View sourceclose()
methodvoid close()answerFor()
methodObject? answerFor(String questionId)Parameters
Prop
Type
Returns Object?
setAnswer()
methodvoid setAnswer(String questionId, Object? value)Parameters
Prop
Type
toggleChoice()
methodvoid toggleChoice(String questionId, String value)Toggle a value within a multi-select answer.
Parameters
Prop
Type
next()
methodFuture<void> next()Advance to the next question, or complete on the last.
View sourceback()
methodvoid back()complete()
methodFuture<void> complete()dismiss()
methodFuture<void> dismiss()NexusQuestionBuilder
typedeftypedef NexusQuestionBuilder = Widget Function(BuildContext context, NexusSurveyController controller, NexusSurveyQuestion question)Override the rendering of a single question. Return your own widget; read the
current value with controller.answerFor(question.id) and write it with
controller.setAnswer(...) / controller.toggleChoice(...).
NexusSurveyView
classclass NexusSurveyView extends StatefulWidgetThe built-in survey card. Renders one question at a time with progress, a
thank-you screen, and default widgets per question type. Pass a
questionBuilder to override individual questions, or replace the whole card
via NexusSurveyOverlay(surveyBuilder: ...).
NexusSurveyView
constructorconst NexusSurveyView({super.key, required this.controller, this.questionBuilder})Parameters
Prop
Type
controller
fieldfinal NexusSurveyController controllerquestionBuilder
fieldfinal NexusQuestionBuilder? questionBuilderNexusSurveyBuilder
typedeftypedef NexusSurveyBuilder = Widget Function(BuildContext context, NexusSurveyController controller)Fully replace the survey UI. You receive the NexusSurveyController; render
whatever you want and drive it (answers, next/back, complete, dismiss, close).
NexusSurveyOverlay
classclass NexusSurveyOverlay extends StatefulWidgetHosts the currently-active survey above your app. Add it via
MaterialApp.builder so it has a Material/Overlay/MediaQuery ancestor:
MaterialApp(
builder: (context, child) => NexusSurveyOverlay(child: child!),
// ...
)Bring your own UI with surveyBuilder (whole card) or questionBuilder (per
question) — otherwise the built-in NexusSurveyView is used.
NexusSurveyOverlay
constructorconst NexusSurveyOverlay({super.key, required this.child, this.surveyBuilder, this.questionBuilder})Parameters
Prop
Type
child
fieldfinal Widget childsurveyBuilder
fieldfinal NexusSurveyBuilder? surveyBuilderquestionBuilder
fieldfinal NexusQuestionBuilder? questionBuilder