survey_kit library
The main entry point for the survey_kit package.
Import this library to access SurveyKit, all AnswerFormat types, SurveyFlow, Step, SurveyResult, and navigation rules.
Classes
- AnswerFormat
- Abstract base class for all answer format types. Defines how a survey question accepts user input. Use AnswerFormat.fromJson for deserialization. Register custom types with registerFromJson.
- BooleanAnswerFormat
-
Answer format that presents a yes/no choice. Renders as two mutually
exclusive buttons. The JSON type identifier is
'bool'. - CloseSurvey
- Closes the survey with FinishReason.discarded, recording questionResult for the current step.
- A NavigationRule that routes to different steps based on the current answer. Provide resultToStepIdentifierMapper to implement custom routing logic. For JSON-driven surveys, the 'values' map in JSON is used to look up the next step ID from the string representation of the answer.
- Content
- Abstract base for all content types displayed on a Step. Content items control what is rendered before the answer widget (text, images, markdown, etc.). Use Content.fromJson for deserialization. Register custom types with registerFromJson.
- ContentWidget
- DateAnswerFormat
-
Answer format that presents a date picker.
The JSON type identifier is
'date'. - DateAnswerView
-
A NavigationRule that always routes to a specific step, regardless of user
input. The JSON type identifier is
'direct'. - DoubleAnswerFormat
-
Answer format for a decimal number entry. Renders as a text field that
accepts floating-point values. The JSON type identifier is
'double'. - DoubleAnswerView
- FinishSurvey
- End the survey immediately.
- ImageContent
-
Content that displays an image loaded from a URL.
The JSON type identifier is
'image'. - IntegerAnswerFormat
-
Answer format for a whole number entry. Renders as a text field that
accepts integer values. The JSON type identifier is
'integer'. - IntegerAnswerView
- LinkText
- LoadingSurveyState
- Initial state while the survey is being initialized.
- MarkdownContent
-
Content that renders a markdown string.
The JSON type identifier is
'markdown'. -
MultipleChoiceAnswerFormat<
T extends TextChoice> -
Answer format that allows selecting multiple items from a list of
TextChoices. The JSON type identifier is
'multi'. - MultipleChoiceAnswerView
- MultipleChoiceAutoCompleteAnswerFormat
-
Answer format that allows selecting multiple items from a searchable
autocomplete list. The JSON type identifier is
'multiple_auto_complete'. - MultipleDoubleAnswerFormat
-
Answer format for entering multiple decimal values at once, each with its
own label. The JSON type identifier is
'multiple_double'. -
Definition of task which can handle routing between
TasksThe navigationRules defines on which StepStepIdentifierwhich next Step is called. The logic which Step is called is defined in the NavigationRule - A TaskNavigator that resolves the next step by evaluating NavigationRules defined in a SurveyFlow. Supports both DirectNavigationRule and ConditionalNavigationRule. Falls back to sequential order when no rule is defined for the current step.
- Proceed to the next step in the list (sequential fallthrough).
- Navigate to the step with stepId.
- Abstract base for navigation rules that determine which step follows a given step. The two built-in subtypes are DirectNavigationRule and ConditionalNavigationRule. Custom rules can be added by implementing this class.
- The return type of ConditionalNavigationRule.resultToStepIdentifierMapper.
- NextStep
- Advances the survey to the next step, recording questionResult for the current step.
- OrderedTask
- Legacy linear task model.
- A TaskNavigator that advances steps strictly in list order. Does not evaluate any navigation rules.
- PresentingSurveyState
- Active state while a step is being presented to the user.
- QuestionAnswer
- ScaleAnswerFormat
-
Answer format that presents a slider for picking a value in a range.
The JSON type identifier is
'scale'. - ScaleAnswerView
- SectionContent
-
Content that displays a structured section with a title, subtitle, and body
text, each as a StyledTextContent. The JSON type identifier is
'section'. -
SingleChoiceAnswerFormat<
T extends TextChoice> -
Answer format that allows selecting exactly one item from a list of
TextChoices. The JSON type identifier is
'single'. - SingleChoiceAnswerView
- StartSurvey
- Starts the survey and transitions from LoadingSurveyState to PresentingSurveyState.
- Step
- A single unit of a survey. A step can display content (text, images, markdown) and optionally collect a user answer via answerFormat. Steps are identified by id which is auto-generated if not provided.
- StepBack
- Returns to the previous step, recording questionResult for the current step.
-
StepResult<
T> -
The result produced by a single Step. Captures the user's answer together
with timing metadata. The generic type
Tis the answer value type. - StyledTextContent
-
Content that displays styled text with configurable font size, weight, and
decoration. The JSON type identifier is
'styledText'. - SurveyAppBar
- SurveyConfiguration
- An InheritedWidget that propagates survey-level configuration down the widget tree. Access with SurveyConfiguration.of(context).
- SurveyController
- Controls survey navigation programmatically. Attach to SurveyKit.surveyController to intercept or trigger navigation events. All navigation methods dispatch events to SurveyStateProvider.
- SurveyDefinition
- Abstract definition of a survey.
- SurveyEvent
- Base class for all events dispatched to SurveyStateProvider.onEvent.
- SurveyFlow
- Unified survey flow model for both linear and branching experiences.
- SurveyKit
- The root widget for a survey experience. Provide a SurveyDefinition via task and receive results via onResult. Customize navigation with surveyController, appearance with surveyProgressbarConfiguration and appBar, and extend with answerViewBuilders, contentWidgetBuilders, or registries.
- SurveyKitLocalizations
-
Callers can lookup localized strings with an instance of SurveyKitLocalizations
returned by
SurveyKitLocalizations.of(context). - SurveyKitPlugin
- Base class for SurveyKit plugins. A plugin registers custom AnswerViewBuilders and ContentWidgetBuilders that extend the survey's built-in rendering capabilities. Pass plugin instances to SurveyKit.registries.
- SurveyPage
- Internal page host for the survey navigator. Manages the initial route and step transitions.
- SurveyProgress
- SurveyProgressConfiguration
- Configuration for the progress bar displayed in the survey app bar. Control visibility, color, size, and whether a textual label is shown.
- SurveyResult
- The aggregated result of a completed or closed survey. Contains all StepResults collected during the session plus timing and finish metadata.
- SurveyResultState
- Terminal state emitted when the survey finishes or is closed. Contains the final SurveyResult.
- SurveyState
- Base class for all survey states. Observe this via SurveyStateProvider to react to survey lifecycle changes.
- SurveyStateProvider
- An InheritedWidget that provides immutable access to survey state.
- SurveyStateProviderWidget
- A StatefulWidget that manages the mutable state for the survey.
- Abstract navigator that drives step-by-step progression through a SurveyDefinition. Subclasses implement the step resolution logic for ordered and branching flows.
- TextAnswerFormat
-
Answer format for free-text entry. The JSON type identifier is
'text'. - TextAnswerView
- TextChoice
- A labeled option used in single- and multiple-choice answer formats. Each choice has a display text and an optional value used for logic/JSON, and a unique id.
- TextContent
-
Content that displays a plain text string.
The JSON type identifier is
'text'. - TimeAnswerFormat
-
Answer format that presents a time picker.
The JSON type identifier is
'time'. - TimeAnswerView
Enums
- BooleanResult
- The result of a BooleanAnswerFormat question. none means no selection, positive means yes, negative means no.
- FinishReason
- Describes how a survey session ended. saved — saved mid-flow, discarded — user closed without completing, completed — all steps finished, failed — an error occurred.
Mixins
-
AnswerMixin<
T extends StatefulWidget, R> - A State mixin for answer view widgets. Connects the answer view to the surrounding QuestionAnswer widget. Call onChange whenever the user's selection changes. Call initValidation in initState to sync the initial state.
-
MeasureDateStateMixin<
T extends StatefulWidget> - A State mixin that records the DateTime when the state is initialized. Mix this into any answer view state to capture when the user first saw the step.
Extensions
Constants
- smallVerticalSpacer → const SizedBox
- A vertical SizedBox with 12 px height, used for standard spacing between elements.
- verySmallVerticalSpacer → const SizedBox
- A vertical SizedBox with 8 px height, used for compact spacing between elements.
Properties
- platformViewRegistry → PlatformViewRegistryShim
-
final
Functions
-
CompletionStep(
{String? id, required String title, required String text, String? buttonText}) → Step - It is uppercase to support previous implementions of the CompletionnStep
-
InstructionStep(
{String? id, required String title, required String text, String? buttonText}) → Step - It is uppercase to support previous implementions of the InstructionStep
-
lookupSurveyKitLocalizations(
Locale locale) → SurveyKitLocalizations -
QuestionStep(
{String? id, required String title, String text = '', required AnswerFormat answerFormat, bool isOptional = true, String? buttonText}) → Step - It is uppercase to support previous implementions of the QuestionStep
-
textFieldInputDecoration(
{String hint = ''}) → InputDecoration
Typedefs
- AnswerViewBuilder = Widget Function(AnswerFormat answerFormat, Step step, StepResult? stepResult)
- A factory function that builds the answer widget for a given AnswerFormat and Step.
- ContentWidgetBuilder = Widget Function(Content content)
- A factory function that builds the display widget for a given Content.
- StepShell = Widget Function(Step step, Widget? answerWidget, BuildContext context)
- A builder function for customizing the container around each survey step. Receives the current Step, the built answer widget (may be null for content-only steps), and the BuildContext.
- Task = SurveyDefinition
- Legacy name for SurveyDefinition.
Exceptions / Errors
- RuleNotDefinedException
- Thrown when a NavigationRule.fromJson call encounters an unrecognized rule type.
- TaskNotDefinedException
- Thrown when a SurveyDefinition.fromJson call encounters an unrecognized task type.