Session class Null safety

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.


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 [...]


asMap Map<String, String>
Returns the session data as Map
createdTime DateTime
CreatedTime is when the session was created
hashCode int
The hash code for this object. [...]
read-only, inherited
id String
Session ID
keys Iterable<String>
Returns keys in session store
needsUpdate bool
Indicates whether session needs update
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


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 non-existent method or property is accessed. [...]
remove(String key) String?
Remove a session key:value by key [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]
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
rand Random
Random number generator used to create session IDs among other things.