DeadSimpleChat Flutter Widget

Add Highly Scaleable Chat to your Flutter Application in Minutes with DeadSimpleChat Flutter Chat SDK.

This widget uses a DeadSimpleChatController to handle the chat operations like sending messages, replying, banning users, and so on. The DeadSimpleChat widget also provides a wide range of event listeners that you can use to listen to the various events in your chat room.

Features

  • Real-time communication.
  • Multi-channel support.
  • Direct messaging.
  • Message history.
  • Message reactions.
  • User banning/unbanning.
  • Customizable UI.
  • Translation support.

Installation

To install the DeadSimpleChat, add the following to your pubspec.yaml:

dependencies:
  deadsimplechat_sdk_flutter: latest_version

Usage

To use the DeadSimple Chat widget in your application, first import it.

import 'package:deadsimplechat_sdk_flutter/deadsimplechat_sdk_flutter.dart';

Then, instantiate it with the required parameters:

DeadSimpleChat(
  roomId: 'roomId',
  publicKey: 'publicKey',
  controller: DeadSimpleChatController(),
  onMessageReceived: (message) => print('Message received: $message'),
);

Using the DeadSimpleChatController

The DeadSimpleChatController provides various methods that you can call to perform different actions in your chat room.

Here is a simple usage of the DeadSimpleChatController:

final chatController = DeadSimpleChatController();

// Call this method to send a message
chatController.sendMessage('Hello, World!');

// Call this method to get the online users
var onlineUsers = await chatController.getOnlineUsers();

// Call this method to get messages
var messages = await chatController.getMessages();

// Call this method to logout
chatController.logout();

Here are the available methods in the DeadSimpleChatController class:

Method Name Description Parameters
connect() Connects to the chat. None
joinRoom(JoinOptions options) Joins a chat room with the specified join options. options - object containing join options
getOnlineUsers() Retrieves the list of online users in the chat. None
getMessages(int skip) Retrieves the messages in the chat, starting from the given skip index. skip - index to start retrieving messages
sendMessage(String message) Sends a chat message to the chat. message - message to send
replyMessage(String messageId, String message) Replies to a specific chat message with the provided message. messageId - ID of the message
message - reply message
getActiveChannels() Retrieves the list of active channels in the chat. None
selectChannel(String channelId) Selects a specific channel to display in the chat. channelId - ID of the channel
getChannelMessages(String channelId, int skip) Retrieves the messages in a specific channel, starting from the given skip index. channelId - ID of the channel
skip - index to start retrieving messages
sendChannelMessage(String message, String channelId) Sends a message to a specific channel with the provided message and channel ID. message - message to send
channelId - ID of the channel
replyChannelMessage(String messageId, String channelId, String message) Replies to a specific channel message with the provided message, message ID, and channel ID. messageId - ID of the message
channelId - ID of the channel
message - reply message
getActiveConversations() Retrieves the list of active conversations in the chat. None
openConversation(String conversationId) Opens a specific conversation in the chat. conversationId - ID of the conversation
createConversation(String userId) Creates a new conversation with the specified user. userId - ID of the user
sendPrivateMessage(String message, String conversationId) Sends a private message to a conversation with a specific message and conversation ID. message - message to send
conversationId - ID of the conversation
likeMessage(String messageId, String reaction, String action) Likes a specific chat message with the specified reaction and action. messageId - ID of the message
reaction - type of reaction
action - type of action
likeChannelMessage(String channelId, String messageId, String reaction, String action) Likes a specific channel message with the provided channel ID, message ID, reaction, and action. channelId - ID of the channel
messageId - ID of the message
reaction - type of reaction
action - type of action
approveMessage(String messageId) Approves a specific chat message with the given message ID. messageId - ID of the message
deleteMessage(String messageId) Deletes a specific chat message with the given message ID. messageId - ID of the message
approveChannelMessage(String messageId, String channelId) Approves a specific channel message with the given message ID and channelID. messageId - ID of the message
channelId - ID of the channel
deleteChannelMessage(String messageId, String channelId) Deletes a specific channel message with the given message ID and channel ID. messageId - ID of the message
channelId - ID of the channel
banUser(String userId) Bans a specific user from the chat. userId - ID of the user
banIp(String ip) Bans a specific IP address from the chat. ip - IP address to ban
getBannedUsers() Retrieves the list of banned users in the chat. None
unBanUser(String userId) Unbans a specific user from the chat. userId - ID of the user
unBanIp(String ip) Unbans a specific IP address from the chat. ip - IP address to unban
loadCustomization(Object customization) Loads a customization object to customize the chat appearance. customization - object containing customization details
loadTranslation(Object translation) Loads a translation object to translate the chat. translation - object containing translation details
logout() Logs out the current user from the chat. None

JoinOptions

The JoinOptions class is used to provide joining parameters when using DeadSimpleChatController.joinRoom() method. Here's an example:

final joinOptions = JoinOptions(
  // Recommended way
  uniqueUserIdentifier: 'cc8459b0-70b9-4bac-b472-b2d36dc3452e	'
  // Recommended way
  accessToken: 'accessToken', 
  // Not Recommended
  username: 'john_doe',
  email: 'john.doe@example.com',
  password: 'password',
  roomPassword: 'roomPassword',
);

chatController.joinRoom(joinOptions);

Event Listeners

The DeadSimpleChat widget provides a variety of event listeners that you can use to listen to events in your chat room. For example, to listen to when a message is received, you can do:

DeadSimpleChat(
  // other parameters
  onMessage: (message) => print('Message received: $message'),
);
  • onMessage(Object message): Invoked when a new chat message is received.
  • onChannelSelected(String channelId): Invoked when a channel is selected in the chat.
  • onRoomJoined(String roomId): Invoked when the chat room is joined successfully.
  • onMessageHistory(String messageId): Invoked when the message history is fetched successfully.
  • onMessageApproved(String messageId): Invoked when a chat message is approved.
  • onMessageDeleted(String messageId): Invoked when a chat message is deleted.
  • onUpdateUsers(String userId): Invoked when the list of online users is updated.
  • onInvalidRoomPassword(String roomId): Invoked when an invalid room password is provided.
  • onRoomLimitReached(String roomId): Invoked when the room limit is reached.
  • onNotAuthorized(String errorMessage): Invoked when the user is not authorized to perform an action.
  • onMessageLiked(String messageId): Invoked when a chat message is liked.
  • onConversationCreated(String userId): Invoked when a conversation is created.
  • onConversationMessage(String conversationId): Invoked when a conversation message is received.
  • onChannelCreated(String channelId): Invoked when a channel is created.
  • onChannelMessage(String channelId): Invoked when a channel message is received.
  • onChannelMessageDeleted(String messageId): Invoked when a channel message is deleted.
  • onChannelMessageApproved(String messageId): Invoked when a channel message is approved.
  • onChannelMessageLiked(String messageId): Invoked when a channel message is liked.
  • onConnectError(String errorMessage): Invoked when an error occurs while connecting to the chat server.
  • onConnectSuccess(String message): Invoked when the chat server connection is successful.
  • onJoinRoomError(String errorMessage): Invoked when an error occurs while joining the chat room.
  • onLoadCustomizationSuccess(String message): Invoked when the customization is loaded successfully.
  • onLoadCustomizationError(String errorMessage): Invoked when an error occurs while loading the customization.
  • onLoadTranslationSuccess(String message): Invoked when the translation is loaded successfully.
  • onLoadTranslationError(String errorMessage): Invoked when an error occurs while loading the translation.
  • onSendMessageError(String errorMessage): Invoked when an error occurs while sending a chat message.

Customizations and Translations

The DeadSimpleChat widget provides options for customizations and translations. Use DeadSimpleChatController.loadCustomization() and DeadSimpleChatController.loadTranslation() methods to load your custom configurations and translations respectively.

chatController.loadCustomization(myCustomization);
chatController.loadTranslation(myTranslation);