Applozic flutter chat plugin
A flutter wraper for Applozic native android and iOS SDKs.
Getting Started
Sign up for Applozic to get your application Id. This application Id is used to login user to applozic.
Prerequisites
Apps using Applozic can target Xcode 13 or later and AndroidX is required.
Installation
- Add the below dependency in your pubspec.yaml file:
dependencies:
# other dependencies
applozic_flutter: ^0.2.0
- Install the package as below:
flutter pub get
- For iOS, navigate to your App/iOS directory from terminal and run the below command:
pod install
Note: Applozic iOS requires min iOS platform version 12 and uses dynamic frameworks. Make sure you have the below settings at the top of your iOS/Podfile:
platform :ios, '12.0'
use_frameworks!
- Import the applozic_flutter in your .dart file to use the methods from Applozic:
import 'package:applozic_flutter/applozic_flutter.dart';
Authentication
Login
Create Applozic user and pass user to login() function as below:
dynamic user = {
'applicationId': "<APPLICATION_ID>", //Mandatory
'userId': userId.text, //Mandatory
'displayName': displayName.text,
'password': password.text,
'authenticationTypeId': 1 //Mandatory
};
ApplozicFlutter.login(user).then((response) {
print("Login success : " + response)
}).catchError((error, stack) =>
print("Error while logging in : " + error.toString()));
Note: Please remember you have to log in once and only after you log out you must log in again. Use below code to check if the user is already logged in:
ApplozicFlutter.isLoggedIn().then((isLoggedIn) {
if (isLoggedIn) {
//The user is logged in
} esle {
//The user is not logged in
}
});
Update logged in user details
You can update the logged in user details as below:
dynamic user = {
'displayName': '<New name>'
'imageLink': '<New Image URL>'
}
ApplozicFlutter.updateUserDetail(user)
.then(
(value) => print("User details updated : " + value))
.catchError((e, s) => print(
"Unable to update user details : " + e.toString()));
Get logged in userId
You can get the userId of the logged in user as below:
ApplozicFlutter.getLoggedInUserId().then((userId) {
print("Logged in userId : " + userId);
}).catchError((error, stack) {
print("User get error : " + error);
});
Push Notifications
Refer to this doc link for push notification for Android and iOS
Conversation
Launch main chat screen
Launch the main chat screen as below:
ApplozicFlutter.launchChatScreen();
Launch Chat with a specific User
Launch the conversation with a user by passing the userId as below:
ApplozicFlutter.launchChatWithUser("<USER_ID>");
Launch Chat with a specific Group
Launch the conversation with a group by passing the groupId as below:
ApplozicFlutter.launchChatWithGroupId(<GROUP_ID>)
.then((value) =>
print("Launched successfully : " + value))
.catchError((error, stack) {
print("Unable to launch group : " + error.toString());
});
Create a group
To create a group, you need to create a groupInfo object and then pass it to the create group function as below:
dynamic groupInfo = {
'groupName': "My group",
'groupMemberList': ['userId1', 'userId2'],
'imageUrl': 'https://www.applozic.com/favicon.ico',
'type': 2,
'admin': 'userId1',
'metadata': {
'plugin': "Flutter",
'platform': "Android"
}
};
ApplozicFlutter.createGroup(groupInfo)
.then((groupId) {
print("Group created sucessfully: " + groupId);
ApplozicFlutter.launchChatWithGroupId(groupId)
.then((value) => print("Launched successfully : " + value))
.catchError((error, stack) {
print("Unable to launch group : " + error.toString());
});
})
.catchError((error, stack) =>
print("Group created failed : " + error.toString()));
Add member to group
To add a member to a group you need to great a object with userId of the member to add and the groupId/clientGroupId (either one) of the group:
dynamic detailObject = {
'userId': "userId", //userId of the user to add
'groupId': 123456 //groupId of the group to add the user to
};
Then pass the object to this function:
ApplozicFlutter.addMemberToGroup(detailObject)
.then((value) => {
print("Member added successfully."),
ApplozicFlutter.createToast("Member added successfully.")
})
.catchError((e, s) => {
print("Error adding member."),
ApplozicFlutter.createToast("Error in adding member.")
});
Remove member from group
To add a member to a group you need to great a object with userId of the member to add and the groupId/clientGroupId (either one) of the group:
dynamic detailObject = {
'userId': "userId", //userId of the user to remove
'groupId': 123456 //groupId of the group to remove the user from
};
Then pass the object to this function:
ApplozicFlutter.removeMemberFromGroup(detailObject)
.then((value) => {
print("Member removed successfully."),
ApplozicFlutter.createToast("Member removed successfully.")
})
.catchError((e, s) => {
print("Error removing member."),
ApplozicFlutter.createToast("Error in removing member.")
});
Send message
To send a message to a contact or a group, you must first create a message object:
dynamic message = {
'to': "userId", // to send message to a contact pass the userId of the receiver (You can ignore the groupId in this case)
'groupId': groupId, //to send message to a group pass the groupId (You can ignore the userId in this case)
'message': "message text", // message to send
};
Note: A message object can have more parameters. Refer to this link: https://docs.applozic.com/docs/android-chat-message-api#build-your-ui-from-scratch---message-api
Then pass the message object to this function:
ApplozicFlutter.sendMessage(message)
.then((value) => print("Message sent."))
.catchError((e, s) => print("Error while sending message: " + e.toString()));
Unread message count for contact
To get the unread count for contact, pass the userId of the contact to the function:
ApplozicFlutter.getUnreadCountForContact(userId)
.then((value) => print("Unread count : " + value.toString()))
.catchError((e, s) => print("Error."));
Unread message count for channel
To get the unread count for a channel, create a object with either the groupId
or the clientGroupId
(only one required):
dynamic channelDetails = { //you need to provide only one of the two
'groupId' : 123456,
'clientGroupId' : "clientGroupId"
};
The pass the object to this function:
ApplozicFlutter.getUnreadCountForChannel(channelDetails)
.then((value) => print("Unread count : " + value.toString()))
.catchError((e, s) => print("Error."));
Number of unread chats
Simply call the following function:
ApplozicFlutter.getUnreadChatsCount()
.then((value) => print("Unread chats count : " + value.toString()))
.catchError((e, s) => print("Error."));
Total unread message count
Simply call the following function:
ApplozicFlutter.getTotalUnreadCount()
.then((value) => print("Total unread count : " + value.toString()))
.catchError((e, s) => print("Error."));
Add contacts
Add contacts to applozic as below:
dynamic user1 = {
'userId': "user1",
'displayName': "User 1",
"metadata": {
'plugin': "Flutter",
'platform': "Android"
}
};
dynamic user2 = {
'userId': "user2",
'displayName': "User 2",
"metadata": {
'plugin': "Flutter",
'platform': "Android"
}
};
ApplozicFlutter.addContacts([user1, user2])
.then((value) => print("Contact added successfully: " + value))
.catchError((e, s) => print("Failed to add contacts: " + e.toString()));
Logout
Logout from applozic as below:
ApplozicFlutter.logout()
.then((value) =>
print("Logout successfull")
.catchError((error, stack) =>
print("Logout failed : " + error.toString()));
Sample app
You can checkout Applozic Flutter sample app that demonstrates the use of this plugin.
In case of any queries regarding this plugin, write to us at support@applozic.com.