Sendbird Chat SDK for Flutter

Platform Language

Warning Sendbird Chat SDK v3 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK v4 here

Table of contents

  1. Introduction
  2. Requirements
  3. Getting started
  4. Sending your first message
  5. Getting help
  6. Hiring

đź”’ Security tip

When a new Sendbird application is created in the dashboard the default security settings are set permissive to simplify running samples and implementing your first code.

Before launching make sure to review the security tab under ⚙️ Settings -> Security, and set Access token permission to Read Only or Disabled so that unauthenticated users can not login as someone else. And review the Access Control lists. Most apps will want to disable "Allow retrieving user list" as that could expose usage numbers and other information.

Introduction

Through Chat SDK for flutter, you can efficiently integrate real-time chat into your client app. On the client-side implementation, you can initialize, configure and build the chat with minimal effort. On the server-side, Sendbird ensures reliable infra-management services for your chat within the app. This readme provides essential information on the Chat SDK’s structure, supplementary features, and the installation steps.

How it works

  1. A user logs in
  2. User sees a list of channels
  3. Select or create an open channel or a group channel
  4. Through the use of the channel event handler, sends and receives messages to other users in that channel.

Requirements

The minimum requirements for Chat SDK for Flutter are:

  • Xcode or Android studio
  • Dart 2.18.0 or above
  • Flutter 3.3.0 or higher

Getting started

This section gives you information you need to get started with Sendbird Chat SDK for Flutter. Follow the simple steps below to build the Chat SDK into your client app.

Try the sample app

The fastest way to test Sendbird Chat SDK for Flutter is to build your chat app on top of our sample app. To create a project for the sample app, download the app from our GitHub repository. The link is down below.

Step 1: Create a Sendbird application from your dashboard

A Sendbird application comprises everything required in a chat service including users, message, and channels. To create an application:

  1. Go to the Sendbird Dashboard and enter your email and password, and create a new account. You can also sign up with a Google account.
  2. When prompted by the setup wizard, enter your organization information to manage Sendbird applications.
  3. Lastly, when your dashboard home appears after completing setup, click Create + at the top-right corner.

Only one Sendbird application can be integrated per app for your service regardless of the platform. All users within your Sendbird application can communicate with each other across all platforms. This means that your iOS, Android, and web client app users can all send and receive messages with one another without any further setup.

Note: All data is limited to the scope of a single application, and users in different Sendbird applications can't chat with one other.

Step 2: Install packages

Installing the Chat SDK is a simple process if you’re familiar with using external packages or SDK’s in your projects. Follow the steps below via pub.

  • Add following dependency in pubspec.yaml.
dependencies:
  sendbird_sdk: ^3.2.19
  • Run flutter pub get command in your project directory.

Step 3: Use the Chat SDK in Flutter

You can use all classes and methods just with the one import statement as shown below.

import 'package:sendbird_sdk/sendbird_sdk.dart'

Sending your first message

Follow the step-by-step instructions below to authenticate and send your first message.

Authentication

In order to use the features of Sendbird Chat SDK for Flutter, you should initiate the Sendbirdsdk instance through user authentication with Sendbird server. This instance communicates and interacts with the server based on an authenticated user account, allowing the client app to use the Chat SDK's features.

Here are the steps to sending your first message using the Chat SDK:

Step 1: Initialize the Chat SDK

Initializing the Chat SDK allows it to respond to the connection and state changes in your client app. Pass the APP_ID of your Sendbird application as an argument to the appId parameter in the constructor of SendbirdSdk. The constructor of SendbirdSdk creates an instance, thus should be called a single time across your client app. It is recommended that the code for initialization be implemented in the user login view.

final sendbird = SendbirdSdk(appId: APP_ID);

Step 2: Connect to Sendbird server

A user can log in and connect a user to Sendbird server by using a unique user ID or with a user ID and an access token.

A. Using a unique user ID

To connect to Sendbird server, a user is required to log in with a unique ID. A new user can authenticate with any untaken user ID, which gets automatically registered to the Sendbird system. An existing ID can log in directly. The ID must be unique within a Sendbird application to be distinguished from others, such as a hashed email address or phone number in your service.

try {
  final user = await sendbird.connect(userId: USER_ID);
} catch (e) {
  // error
}

B. Using a unique user ID and an access token

By using Chat Platform API, you can create a user and issue a unique access token to each user, or issue an access token for an existing user. Once an access token is issued, a user is required to provide the access token to log in to your Sendbird application.

  1. Using the Chat Platform API, create a Sendbird user account with the information submitted when a user signs up or signs in to your service.
  2. Save the user ID along with the issued access token to your securely managed persistent storage.
  3. When a user attempts to log in to the application, load the user ID and access token from the storage, and then pass them to connect() method.
  4. Periodically replacing the user's access token is recommended for account security.
try {
  final user = await sendbird.connect(userId: USER_ID, accessToken: ACCESS_TOKEN);
} catch (e) {
  // error
}

- Tips for secure user login

To manage user access to your Sendbird application, go to Settings > Application > Security > Access token permission setting on your Sendbird dashboard. You can change settings to prevent the users without an access token from logging in to your application or restrict their access to read and write messages.

For security reasons, you can also use a session token when a user logs in to Sendbird server instead of an access token. Learn more about Access token vs. Session token from the Chat Platform API guide.

Step 3: Create a new open channel

Create an open channel. Once created, all users in your Sendbird application can easily participate in the channel.

try {
  final channel = await OpenChannel.createChannel();
} catch (e) {
  // error
}

You can also create a group channel by inviting users as new members to the channel.

Note: The majority of the methods used in the following steps are all asynchronous. This means, with asynchronous methods, your client app must receive a result via await or then() callbacks from Sendbird server through completion handlers before moving on to the next step.

Step 4: Enter the channel

Enter the channel to send and receive messages.

try {
  final channel = await OpenChannel.getChannel(CHANNEL_URL);
  await channel.enter();
} catch (e) {
  // error
}

Step 5: Send a message to the channel

Finally, send a message to the channel. There are three types of messages: a user message in a plain text, a file message in a binary file, such as an image or PDF, and an admin message in a plain text sent through the dashboard or Chat Platform API.

try {
  final params = UserMessageParams()
    ..message = MESSAGE
    ..data = DATA
    ..customType = CUSTOM_TYPE;

  final preMessage = openChannel.sendUserMessage(params, onCompleted:(message, error){
      if (error != null) {
        // error
      } else {
        // message is sent successfully
      }
  });
  // use preMessage to populate your chat messages early
} catch (e) {
  // error
}

Getting Help

Check out the Official Sendbird Flutter docs and Sendbird's Developer Portal for tutorials and videos. If you need any help in resolving any issues or have questions, visit our community forums.


We are Hiring!

Sendbird is made up of a diverse group of humble, friendly, and hardworking individuals united by a shared purpose to build the next generation of mobile & social technologies. Join our team remotely or at one of our locations in San Mateo, Seoul, New York, London, and Singapore. More information on a careers page.

Libraries

core/message/admin_message
services/network/api_client
request/abstract/api_request
core/models/app_info
core/models/apple_critical_alert_options
request/user/list/application_user_list_request
utils/async/async_operation
utils/async/async_queue
handlers/authenticate_event_handler
query/user_list/banned_user_list_query
request/user/list/banned_user_list_request
core/channel/base/base_channel
events/base_event
core/message/base_message
params/base_message_fetch_params
core/message/base_message_internal
params/base_message_params
query/base_query
query/user_list/blocked_user_list_query
request/user/list/blocked_user_list_request
services/db/cache_service
services/db/cache_utils
services/db/cached_meta_data/cached_data
services/db/cached_meta_data/cached_data_map
events/channel_event
handlers/channel_event_handler
request/user/preference/channel_invitation_preference_request
request/moderation/channel_my_mute_info_get_request
request/reaction/channel_reaction_add_request
request/reaction/channel_reaction_remove_request
request/report/channel_report_request
request/moderation/channel_user_ban_request
request/moderation/channel_user_mute_request
request/moderation/channel_user_unban_request
request/moderation/channel_user_unmute_request
core/models/command
managers/command_manager
constant/command_type
handlers/connection_event_handler
managers/connection_manager
constant/contants
request/channel_meta_counter/create_request
request/user_meta_data/create_request
request/channel_meta_data/create_request
request/channel_meta_counter/delete_request
request/user_meta_data/delete_request
request/channel_meta_data/delete_request
features/delivery/delivery_status
request/user/preference/do_not_disturb_request
core/models/emoji
request/general/emoji_category_request
request/general/emoji_container_request
request/general/emoji_request
constant/enums
core/models/error
constant/error_code
managers/event_manager
utils/extensions
core/models/file_info
core/message/file_message
params/file_message_params
request/messages/file_message_resend_request
request/messages/file_message_send_request
request/messages/file_message_update_request
request/channel/file_upload_request
request/channel_meta_data/get_request
request/channel_meta_counter/get_request
core/channel/group/group_channel
request/channel_operation/group_channel_accept_request
request/channel/group_channel_change_log_request
params/group_channel_change_logs_params
request/channel_preference/group_channel_count_preference_request
request/user/count/group_channel_count_request
request/channel/group_channel_create_request
request/channel_operation/group_channel_decline_request
request/channel/group_channel_delete_request
request/feature/group_channel_delivery_request
core/models/group_channel_filters
request/channel_preference/group_channel_freeze_request
request/channel_preference/group_channel_hide_request
core/channel/group/group_channel_internal
request/channel_operation/group_channel_invite_request
request/channel_operation/group_channel_join_request
request/channel_operation/group_channel_leave_request
query/channel_list/group_channel_list_query
request/channel/group_channel_list_request
query/user_list/group_channel_member_list_query
params/group_channel_params
request/channel_preference/group_channel_push_trigger_option_request
request/feature/group_channel_read_request
request/channel/group_channel_refresh_request
request/channel_operation/group_channel_reset_history_request
request/channel_preference/group_channel_screen_shot_request
params/group_channel_total_unread_channel_count_params
params/group_channel_total_unread_message_count_params
request/feature/group_channel_typing_request
request/channel/group_channel_update_request
services/network/http_client
request/user/info_update_request
utils/isolate/isolate_bridge_def
utils/isolate/isolate_bridge_master
utils/isolate/isolate_bridge_slave
utils/json_from_parser
utils/logger
events/login_event
request/general/mack_request
events/mcnt_event
core/models/member
request/user/list/member_list_request
services/db/memory_cache_service
request/messages/message_change_log_get_request
params/message_change_logs_params
request/messages/message_copy_request
request/messages/message_delete_request
events/message_event
request/messages/message_get_request
params/message_list_params
request/messages/message_meta_array_request
request/report/message_report_request
params/message_retrieval_params
query/search/message_search_query
request/messages/message_search_request
request/messages/message_translate_request
request/messages/messages_get_request
core/models/meta_array
query/user_list/muted_user_list_query
request/user/list/muted_user_list_request
features/og_meta_data/og_image
features/og_meta_data/og_interfaces
features/og_meta_data/og_meta_data
core/channel/open/open_channel
request/channel/open_channel_create_request
request/channel/open_channel_delete_request
request/channel_operation/open_channel_enter_request
request/channel_operation/open_channel_exit_request
query/channel_list/open_channel_list_query
request/channel/open_channel_list_request
params/open_channel_params
request/channel/open_channel_refresh_request
request/channel/open_channel_update_request
request/channel/operator_add_request
query/user_list/operator_list_query
request/user/list/operator_list_request
request/channel/operator_remove_request
core/models/options
utils/parsers
query/user_list/participant_list_query
request/user/list/participant_list_request
request/pin/pin_create_request
request/pin/pin_delete_request
services/db/policy
features/poll/poll
request/poll/poll_changelogs_get_request
params/poll_changelogs_params
request/poll/poll_close_request
request/poll/poll_create_request
features/poll/poll_data
request/poll/poll_delete_request
request/poll/poll_get_request
handlers/poll_handler
request/poll/poll_list_get_request
query/poll_list/poll_list_query
params/poll_list_query_params
features/poll/poll_option
request/poll/poll_option_add_request
request/poll/poll_option_delete_request
request/poll/poll_option_get_list_voters_request
request/poll/poll_option_get_request
handlers/poll_option_handler
params/poll_option_retrieval_params
request/poll/poll_option_update_request
params/poll_params
params/poll_retrieval_params
events/poll_update_event
params/poll_update_params
request/poll/poll_update_request
events/poll_vote_event
request/poll/poll_vote_request
query/poll_list/poll_voter_list_query
params/poll_voter_list_query_params
query/message_list/previous_message_list_query
query/channel_list/public_group_channel_list_query
request/channel/public_group_channel_list_request
request/user/push/push_register_request
request/user/preference/push_sound_request
request/user/preference/push_template_request
request/user/preference/push_trigger_option_request
request/user/push/push_unregister_request
features/reaction/reaction
features/reaction/reaction_event
features/delivery/read_status
core/models/reconnect_configuration
core/models/reconnect_task
core/models/responses
core/models/restricted_user
core/message/scheduled_file_message
params/scheduled_file_message_params
request/messages/scheduled_file_message_request
request/messages/scheduled_file_message_send_request
params/scheduled_file_message_update_params
request/messages/scheduled_file_message_update_request
features/scheduled_message/scheduled_info
request/messages/scheduled_message_cancel_request
request/messages/scheduled_message_get_list_request
request/messages/scheduled_message_get_request
params/scheduled_message_list_params
query/scheduled_message/scheduled_message_list_query
params/scheduled_message_retrieval_params
request/messages/scheduled_message_send_now_request
params/scheduled_message_total_count_params
request/messages/scheduled_message_total_count_request
core/message/scheduled_user_message
params/scheduled_user_message_params
request/messages/scheduled_user_message_request
request/messages/scheduled_user_message_send_request
params/scheduled_user_message_update_params
request/messages/scheduled_user_message_update_request
sendbird_sdk
Sendbird SDK for flutter
sdk/internal/sendbird_sdk_accessor
sdk/sendbird_sdk_api
sdk/internal/sendbird_sdk_internal
sdk/internal/sendbird_sdk_streams
core/models/sender
events/session_event
handlers/session_event_handler
request/general/session_key_update_request
managers/session_manager
request/user/session/session_token_issue_request
request/user/session/session_token_revoke_request
request/user/preference/snooze_request
core/models/state
utils/string_utils
features/threading/thread_info
features/threading/thread_info_update_event
params/threaded_message_list_params
constant/types
features/typing/typing_status
request/user/count/unread_channel_count_request
core/models/unread_count_info
core/models/unread_item_count
request/user/count/unread_item_count_request
request/user/count/unread_message_count_request
request/channel_meta_counter/update_request
request/user_meta_data/update_request
request/channel_meta_data/update_request
core/models/user
request/user/block/user_block_request
events/user_event
handlers/user_event_handler
request/user/list/user_list_query
query/user_list/user_list_query
core/message/user_message
params/user_message_params
request/messages/user_message_resend_request
request/messages/user_message_send_request
request/messages/user_message_update_request
request/report/user_report_request
request/user/block/user_unblock_request
services/network/websocket_client
request/abstract/ws_event
request/abstract/ws_request