Session class

A per-request object containing session information of the request

id field uniquely identifies the session.

needsUpdate reflects if the session has been updated during the current request.

createdTime is the time at which the session was created. It can be used to implement expiry of the session.

Session implements subscript operator, allowing session data to be accessed and updated using normal Map-like operators and methods.

session['email'] = email;
String name = session['name'];

In addition, getInt and getDouble methods can be used to cast the String session value to int and double values respectively.

Constructors

Session(String id, Map<String, String> data, DateTime createdTime, {bool needsUpdate = false})
Creates a session object for existing session with given data, id and createdTime
Session.newSession(Map<String, String> data, {String? id, DateTime? createdTime})
Create new session with given data, id and createdTime

Properties

asMap Map<String, String>
Returns the session data as Map
no setter
createdTime DateTime
CreatedTime is when the session was created
final
hashCode int
The hash code for this object.
no setterinherited
id String
Session ID
final
keys Iterable<String>
Returns keys in session store
no setter
needsUpdate bool
Indicates whether session needs update
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(String key, String value) → void
Set session value by key
addAll(Map<String, String> values) → void
Set multiple session key:value pairs
clear() → void
Removes all the session key:value pairs.
getDouble(String key, [double? defaultVal]) double?
Returns a session value as double by key. Returns defaultVal if the conversion fails.
getInt(String key, [int? defaultVal]) int?
Returns a session value as int by key. Returns defaultVal if the conversion fails.
getList(String key, {String split = ','}) List<String>?
getSet(String key, {String split = ','}) Set<String>?
getString(String key, [String defaultVal = '']) String
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(String key) String?
Remove a session key:value by key
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String key) String?
Access session value by key
operator []=(String key, String value) → void
Set session value by key

Static Properties

newId String
Returns new Session ID
no setter
rand Random
Random number generator used to create session IDs among other things.
final