CrossmintEmailSignInViewModel class final
Headless view model for the SDK's email + OTP sign-in flow. Owns the
state machine (current step, loading flag, error, OTP challenge id,
resend cooldown) and the authentication calls against
CrossmintAuthClient, so the default-UI CrossmintEmailSignIn widget
can become a thin presentational layer and headless consumers can reuse
the same state machine behind their own design system.
The view model does not own text controllers — those are presentation concerns. Consumers pass the trimmed email / OTP strings into sendOtp / confirmOtp / resend and own their own input widgets.
Lifecycle: consumers must call dispose when the view model is no longer needed so the internal resend-cooldown timer is cancelled.
- Inheritance
-
- Object
- ChangeNotifier
- CrossmintEmailSignInViewModel
Constructors
- CrossmintEmailSignInViewModel({required CrossmintAuthClient auth, Duration cooldownDuration = const Duration(seconds: 60)})
Properties
- canResend → bool
-
True when resend can be invoked: the cooldown has elapsed and no
operation is currently in flight.
no setter
- cooldownDuration → Duration
-
Duration of the resend cooldown. Defaults to 60 seconds to match the
React Native Crossmint SDK. Lowered in tests to keep them fast.
final
- cooldownRemaining → int
-
Seconds remaining before resend becomes available again. Zero when
the cooldown is not active.
no setter
- emailId → String?
-
The OTP challenge id returned by CrossmintAuthClient.sendEmailOtp,
required for the subsequent confirm call.
nulluntil sendOtp succeeds.no setter - error → String?
-
Localized error message from the last failed operation, or
nullif the flow is in a clean state.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isLoading → bool
-
True while a network call (send, confirm, or resend) is in flight.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- step → CrossmintEmailSignInStep
-
Current step in the sign-in flow.
no setter
- submittedEmail → String
-
The email address the user successfully submitted. Empty string until
sendOtp succeeds.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
confirmOtp(
String code) → Future< bool> -
Confirm the OTP challenge with
code. Returnstrueif the verification succeeded,falseif the code was rejected, and rethrows on a non-validation error (after storing the error on error and notifying listeners). -
dispose(
) → void -
Discards any resources used by the object.
override
-
goBackToEmail(
) → void - Return to the email-input step. Cancels the resend cooldown, clears any displayed error, and preserves submittedEmail / emailId in case the consumer wants to re-use them (e.g. for a "wrong email" confirmation dialog).
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
resend(
) → Future< void> - Re-send the OTP challenge for the previously-submitted email. No-op when the resend cooldown has not yet elapsed or when an operation is already in flight. On success the cooldown restarts; on failure the error is stored on error and the cooldown is not touched.
-
sendOtp(
String email) → Future< void> -
Send an OTP challenge for
email. On success, transitions to CrossmintEmailSignInStep.otpInput and starts the resend cooldown. On failure, stores the error message on error and stays on the email-input step. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited