Fluxy
Fluxy Plugins

Presence (Collaboration)

Real-time user states, online status, and typing indicators.

Presence (Collaboration)

The fluxy_presence plugin provides real-time user-state tracking. This is essential for collaborative applications where you need to show who is online, who is in the same document/room, and who is currently typing.

Installation

Add the dependency to your pubspec.yaml:

dependencies:
  fluxy_presence: ^1.0.0

Or use the Fluxy CLI:

fluxy module add presence

Key Features

  • Online List: Reactive signal for all active users in a real-time session.
  • Typing Indicators: Track when other users are typing messages or editing data.
  • Live Lifecycle: Automatically handles join, leave, and disconnect events.
  • WebSocket Integration: Wires directly into fluxy_websocket for zero-latency updates.

Usage

1. Initialize

Presence typically requires an active real-time connection.

final presence = Fluxy.register(FluxyPresencePlugin());

2. Monitor Online Users

The users signal is an ObservableList of FluxyUserPresence objects.

Fx(() {
  return Fx.row([
    Fx.text('Who is here?').font.bold(),
    ...presence.users.value.map((user) => 
      Fx.avatar(user.avatar).tooltip(user.name)
    )
  ]);
});

3. Typing Indicators

Broadcast your own typing status and listen for others.

// Local user typing
Fx.input(
  signal: chatMessage,
  onChanged: (val) => presence.setTyping(val.isNotEmpty),
);

// Global typing status
Fx(() {
  if (presence.typingUsers.value.isNotEmpty) {
    return Fx.text('Someone is typing...').italic().muted();
  }
  return const SizedBox.shrink();
});

API Reference

Signals

SignalTypeDescription
usersFlux<List<User>>Live list of users in the current room.
typingUsersFlux<Set<String>>Set of User IDs that are currently typing.
isLocalTypingFlux<bool>Local reactive state for the current device's typing status.

Methods

  • setTyping(bool typing): Broadcasts your typing state across the WebSocket.
  • isUserTyping(String userId): Checks if a specific user is currently active.

Stability Features

  • Auto-Reset: Typing indicators automatically "time out" after 3 seconds of inactivity to prevent stale states if a user closes the app mid-sentence.
  • Batch Updates: Presence lists are handled as reactive atomic updates to prevent UI flicker.
  • Type-Safety: Messages are validated against internal schemas before triggering reactive updates.

On this page