getCurrentSession<State> function

Session<State>? getCurrentSession<State>()

Returns the Session instance active in the current context, or null.

When a State type argument is supplied it is applied to the returned session, so getCustom() / updateCustom(...) are typed. Because Dart generics are reified, the requested State must match the one the session was created with (a mismatch throws on the cast). Defaults to Session<dynamic>? (the untyped view) when no type argument is given.

Implementation

Session<State>? getCurrentSession<State>() =>
    Zone.current[_sessionZoneKey] as Session<State>?;