Session class
The Session Facade.
Provides a Laravel-style flash-data API for surviving navigation: flash input on failed submit, navigate back, repopulate the form with Session.old / Session.error.
// On failed submit:
Session.flash(form.data);
Session.flashErrors({'email': ['Invalid email.']});
MagicRoute.back();
// In the form view:
WFormInput(
initialValue: Session.old('email') ?? '',
);
if (Session.hasError('email'))
WText(Session.error('email')!, className: 'text-red-500');
Flash data survives exactly one navigation. Call Session.tick on every real route change. The router delegate listener can fire for non-navigation events (redirect re-evaluation, notifier rebuilds), so gate the tick on an actual location change:
var lastLocation = MagicRouter.instance.currentLocation;
MagicRouter.instance.routerConfig.routerDelegate.addListener(() {
final currentLocation = MagicRouter.instance.currentLocation;
if (currentLocation == lastLocation) return;
lastLocation = currentLocation;
Session.tick();
});
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- hasFlash → bool
-
Whether any flashed input or error is readable.
no setter
- store → SessionStore
-
The underlying store. Exposed for testing.
no setter
Static Methods
-
error(
String field) → String? - Read the first flashed error for a field.
-
errors(
String field) → List< String> - Read all flashed errors for a field.
-
flash(
Map< String, dynamic> input) → void - Flash input values for the next frame.
-
flashErrors(
Map< String, List< errors) → voidString> > - Flash validation errors for the next frame.
-
hasError(
String field) → bool - Whether the given field has a flashed error.
-
old(
String field, [String? fallback]) → String? - Read a flashed input value as a string.
-
oldInput(
String field, [String? fallback]) → String? - Top-level helper equivalent to old.
-
oldRaw(
String field) → dynamic - Read a flashed input value in its original type.
-
reset(
) → void - Wipe both buckets. Intended for tests.
-
setStore(
SessionStore store) → void - Swap the underlying store (for testing).
-
tick(
) → void - Advance the flash bucket. Call on every navigation.