Browse SDKs · Flutter
Platform
SDKsFlutter

Subscribe to user status

Subscribe to real-time online presence status for specified users using the OpenIM Flutter SDK.

Copy

Subscribe to real-time presence changes for specified target users and retrieve their initial presence snapshot:

Parameters

ParameterTypeRequiredDescription
userIDsList<String>YesList of user IDs whose online status should be subscribed to. Deduplicate and filter out empty strings; subscribe only to users currently visible on screen.

Code example

final states = await OpenIM.iMManager.userManager.subscribeUsersStatus(
  ['user_a', 'user_b'],
);

Return value

A successful Future returns a list of presence status snapshots for the target users at the moment of subscription (List<UserStatusInfo>).

Core fields of each UserStatusInfo:

  • userID: Unique user identifier; acts as the primary key for state lookup and merging.
  • status: Integer representing presence state.
  • detailPlatformStatus: List of platform presence details (iOS, Android, Web, Desktop, etc.).

Merge these snapshot records into your local presence cache using userID.

Listen for presence status updates

Handle presence transitions centrally. When a subscribed user's presence changes (connecting, disconnecting, or changing active platforms), the SDK delivers updates through the onUserStatusChanged callback:

void handleUserStatusChanged(UserStatusInfo info) {
  mergePresence(info);
}

The Flutter SDK maintains a single OnUserListener instance inside UserManager. Configure this callback inside the consolidated application entry point described in Events overview.

When widgets are disposed or users scroll out of the visible viewport, invoke Unsubscribe from user status to release subscription resources.