SurveyNotifier class
Flutter ChangeNotifier that wraps SurveySDK and provides reactive state management for survey-taking UI.
This is the Flutter equivalent of React Native's SurveyProvider. It subscribes to all relevant EventBus events and calls notifyListeners whenever state changes, allowing Consumer/Selector widgets to rebuild automatically.
Usage:
ChangeNotifierProvider(
create: (_) => SurveyNotifier(config, onReady: (s) => print(s.title)),
child: const SurveyScreen(),
)
- Inheritance
-
- Object
- ChangeNotifier
- SurveyNotifier
Constructors
- SurveyNotifier(SurveySDKConfig config, {void onReady(Survey)?, void onError(SdkError)?, void onComplete(SurveyResponse)?})
- Create a SurveyNotifier wrapping a new SurveySDK instance.
Properties
-
answers
→ Map<
String, dynamic> -
All current answers keyed by questionId.
no setter
- canGoNext → bool
-
Whether the user can navigate forward.
no setter
- canGoPrevious → bool
-
Whether the user can navigate backward.
no setter
- currentPage → Page?
-
The current page, or null.
no setter
- currentPageIndex → int
-
The current zero-based page index.
no setter
- error → SdkError?
-
The last error, or null if no error occurred.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isCompleted → bool
-
Whether the survey has been submitted successfully.
no setter
- isError → bool
-
Whether the SDK is in an error state.
no setter
- isInProgress → bool
-
Whether the user is actively filling out the survey.
no setter
- isLastPage → bool
-
Whether the current page is the last page.
no setter
- isLoading → bool
-
Whether the SDK is currently loading the survey.
no setter
- isReady → bool
-
Whether the survey is loaded and ready (no answers yet).
no setter
- isSubmitting → bool
-
Whether the survey is currently being submitted.
no setter
- phase → SurveyPhase
-
The current survey lifecycle phase.
no setter
- progress → ProgressInfo
-
Current progress information.
no setter
- quizResult → QuizResult?
-
The quiz result, or null if not a quiz or not yet scored.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sdk → SurveySDK
-
Get the underlying SurveySDK instance for advanced usage.
no setter
- survey → Survey?
-
The loaded survey, or null if not yet loaded.
no setter
- theme → ResolvedTheme
-
The resolved theme for the survey.
no setter
-
validationErrors
→ Map<
String, List< String> > -
Current validation errors keyed by questionId.
no setter
-
visibleQuestionIds
→ Set<
String> -
IDs of currently visible questions.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
clearAnswer(
String questionId) → void - Clear the answer for a question.
-
dispose(
) → void -
Discards any resources used by the object.
override
-
getAnswer(
String questionId) → dynamic - Get the current answer for a question.
-
getVisibleQuestions(
[int? pageIndex]) → List< Question> - Get visible questions for a page (or the current page).
-
goToPage(
int index) → bool - Jump to a page by index. Returns true if successful.
-
isQuestionRequired(
String questionId) → bool - Check whether a question is currently required.
-
isQuestionVisible(
String questionId) → bool - Check whether a question is currently visible.
-
loadSurvey(
) → Future< void> - Load the survey from the API.
-
nextPage(
) → bool - Navigate to the next page. Returns true if successful.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
previousPage(
) → bool - Navigate to the previous page. Returns true if successful.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
resolvePiping(
String text) → String - Resolve piping placeholders in text.
-
setAnswer(
String questionId, dynamic value) → void - Set an answer for a question.
-
submit(
{String? captchaToken}) → Future< void> - Submit the survey response.
-
toString(
) → String -
A string representation of this object.
inherited
-
validateCurrentPage(
) → Map< String, List< String> > - Validate all questions on the current page.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited