StableUserId class
Persists a stable opaque id per typed display name.
In real production, a chat app gets its userId from an external
auth provider (Cognito sub, Firebase uid, etc.) — an opaque
identifier distinct from the user's display name. Demo / example
apps without that infrastructure still need stable ids so the
backend can key conversations, history and contacts off the same
row across logins.
forDisplayName mints a UUID v4 the first time it sees a name,
persists it under <keyPrefix><name> in SharedPreferences, and
returns the same id on subsequent calls. Useful as a drop-in for
demo/example apps until they wire real auth.
final userId = await StableUserId.forDisplayName('alice');
final config = ChatConfig.withBasicAuth(
username: userId,
...,
);
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 Methods
-
forDisplayName(
String displayName, {SharedPreferences? prefs, String keyPrefix = defaultKeyPrefix}) → Future< String> -
Returns the persisted UUID for
displayName, minting a fresh one when none is stored yet. Whitespace indisplayNameis trimmed and the lookup is case-sensitive — pass the same canonical form (typically lowercased) you intend to use across sessions. -
forget(
String displayName, {SharedPreferences? prefs, String keyPrefix = defaultKeyPrefix}) → Future< void> -
Removes the persisted id for
displayName. The next call to forDisplayName with the same name will mint a fresh UUID. Useful as part of a "wipe demo data" flow.
Constants
- defaultKeyPrefix → const String