Client class

The official Dart client for Stream Chat, a service for building chat applications. This library can be used on any Dart project and on both mobile and web apps with Flutter. You can sign up for a Stream account at https://getstream.io/chat/

The Chat client will manage API call, event handling and manage the websocket connection to Stream Chat servers.

final client = Client("stream-chat-api-key");

Constructors

Client(String apiKey, {TokenProvider tokenProvider, String baseURL: _defaultBaseURL, Level logLevel: Level.WARNING, LogHandlerFunction logHandlerFunction, bool persistenceEnabled: true, Duration connectTimeout: const Duration(seconds: 6), Duration receiveTimeout: const Duration(seconds: 6), Dio httpClient, void showLocalNotification(Message, ChannelModel), Duration backgroundKeepAlive: const Duration(minutes: 1), RetryPolicy retryPolicy})
Create a client instance with default options. You should only create the client once and re-use it across your application.

Properties

apiKey String
Your project Stream Chat api key. Find your API keys here https://getstream.io/dashboard/
final
backgroundKeepAlive Duration
The amount of time that will pass before disconnecting the client in the background
final
baseURL String
Your project Stream Chat base url.
final
connectionId String
The id of the current websocket connection
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
httpClient Dio
Dio httpClient It's be chosen because it's easy to use and supports interesting features out of the box (Interceptors, Global configuration, FormData, File downloading etc.)
@visibleForTesting, read / write
logger Logger
Client specific logger instance. Refer to the class Logger to learn more about the specific implementation.
final
logHandlerFunction LogHandlerFunction
A function that has a parameter of type LogRecord. This is called on every new log record. By default the client will use the handler returned by _getDefaultLogHandler. Setting it you can handle the log messages directly instead of have them written to stdout, this is very convenient if you use an error tracking tool or if you want to centralize your logs into one facility. [...]
read / write
logLevel Level
By default the Chat Client will write all messages with level Warn or Error to stdout. During development you might want to enable more logging information, you can change the default log level when constructing the client. [...]
final
offlineStorage → OfflineStorage
Client offline database
read-only
persistenceEnabled bool
If true chat data will persist on disk
final
retryPolicy → RetryPolicy
The retry policy options getter
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
showLocalNotification → void Function(Message, ChannelModel)
Method used to show a local notification while the app is in background Switching to another application will not disconnect the client immediately So, use this method to show the notification when receiving a new message via events
final
state ClientState
This client state
read / write
stream Stream<Event>
Stream of Event coming from websocket connection Listen to this or use the on method to filter specific event types
read-only
token String
The current user token
read / write
tokenProvider TokenProvider
A function in which you send a request to your own backend to get a Stream Chat API token. The token will be the return value of the function. It's used by the client to refresh the token once expired or to set the user without a predefined token using setUserWithProvider.
final
wsConnectionStatus ValueNotifier<ConnectionStatus>
This notifies the connection status of the websocket connection. Listen to this to get notified when the websocket tries to reconnect.
final

Methods

addDevice(String id, String pushProvider) Future<EmptyResponse>
Add a device for Push Notifications.
banUser(String targetUserID, [Map<String, dynamic> options = const {}]) Future<EmptyResponse>
Bans a user from all channels
channel(String type, {String id, Map<String, dynamic> extraData}) Channel
Returns a channel client with the given type, id and custom data.
connect() Future<Event>
Connect the client websocket
decode<T>(String j, DecoderFunction<T> decoderFunction) → T
Used to log errors and stacktrace in case of bad json deserialization
delete(String path, {Map<String, dynamic> queryParameters}) Future<Response<String>>
Handy method to make http DELETE request with error parsing.
deleteMessage(Message message, [String cid]) Future<EmptyResponse>
Deletes the given message
devToken(String userId) String
Get a development token
disconnect({bool flushOfflineStorage: false}) Future<void>
Closes the websocket connection and resets the client
dispose() → void
Call this function to dispose the client
flagMessage(String messageID) Future<EmptyResponse>
Flag a message
flagUser(String userId) Future<EmptyResponse>
Flag a user
get(String path, {Map<String, dynamic> queryParameters}) Future<Response<String>>
Handy method to make http GET request with error parsing.
getDevices() Future<ListDevicesResponse>
Gets a list of user devices.
getMessage(String messageId) Future<GetMessageResponse>
Get a message by id
handleEvent(Event event) → void
Method called to add a new event to the _controller.
markAllRead() Future<EmptyResponse>
Mark all channels for this user as read
muteUser(String targetID) Future<EmptyResponse>
Mutes a user
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
on([String eventType, String eventType2, String eventType3, String eventType4]) Stream<Event>
Stream of Event coming from websocket connection Pass an eventType as parameter in order to filter just a type of event
patch(String path, {Map<String, dynamic> queryParameters, dynamic data}) Future<Response<String>>
Handy method to make http PATCH request with error parsing.
post(String path, {dynamic data}) Future<Response<String>>
Handy method to make http POST request with error parsing.
put(String path, {Map<String, dynamic> queryParameters, dynamic data}) Future<Response<String>>
Handy method to make http PUT request with error parsing.
queryChannels({Map<String, dynamic> filter, List<SortOption> sort, Map<String, dynamic> options, PaginationParams paginationParams, int messageLimit, bool onlyOffline: false}) Stream<List<Channel>>
Requests channels with a given query.
queryUsers(Map<String, dynamic> filter, List<SortOption> sort, Map<String, dynamic> options) Future<QueryUsersResponse>
Requests users with a given query.
removeDevice(String id) Future<EmptyResponse>
Remove a user's device.
resync([List<String> cids]) Future<void>
Get the events missed while offline to sync the offline storage
A message search.
setAnonymousUser() Future<Event>
Set the current user with an anonymous id, this triggers a connection to the API. It returns a Future that resolves when the connection is setup.
setGuestUser(User user) Future<void>
Set the current user as guest, this triggers a connection to the API. It returns a Future that resolves when the connection is setup.
setUser(User user, String token) Future<Event>
Set the current user, this triggers a connection to the API. It returns a Future that resolves when the connection is setup.
setUserWithProvider(User user) Future<void>
Set the current user using the tokenProvider to fetch the token. It returns a Future that resolves when the connection is setup.
toString() String
Returns a string representation of this object.
inherited
unbanUser(String targetUserID, [Map<String, dynamic> options = const {}]) Future<EmptyResponse>
Remove global ban for a user
unflagMessage(String messageId) Future<EmptyResponse>
Unflag a message
unflagUser(String userId) Future<EmptyResponse>
Unflag a message
unmuteUser(String targetID) Future<EmptyResponse>
Unmutes a user
updateMessage(Message message, [String cid]) Future<UpdateMessageResponse>
Update the given message
updateUser(User user) Future<UpdateUsersResponse>
Update or Create the given user object.
updateUsers(List<User> users) Future<UpdateUsersResponse>
Batch update a list of users

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited