A flutter IM plugin for android and ios

Related tags

Open Source Apps sdk
Overview

flutter_openim_sdk

Download demo

flutter_openim_widget

Chinese

A flutter IM plugin for android and ios.

Getting Started

1,Add dependency in yaml

   flutter_openim_sdk: ^1.0.4

2,Import package

  import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';

3, Init config

// Initialize SDK
   OpenIM.iMManager
      ..initSDK(
        platform: IMPlatform.ios,
    	ipApi: 'Api interface address',
        ipWs: 'WebSocket address',
        dbPath: 'Database directory',
        listener: OnInitSDKListener(
          connecting: () {},
          connectFailed: (code, error) {},
          connectSuccess: () {},
          kickedOffline: () {},
          userSigExpired: () {},
          selfInfoUpdated: (user) {},
        ),
      )

      // Add message listener (remove when not in use)
      ..messageManager.addAdvancedMsgListener(OnAdvancedMsgListener(
        recvMessageRevoked: (id) {},
        recvC2CReadReceipt: (list) {},
        recvNewMessage: (msg) {},
      ))

      // Set up message sending progress listener
      ..messageManager.setMsgSendProgressListener(OnMsgSendProgressListener(
        progressCallback: (id, progress) {},
      ))

      // Set up friend relationship listener
      ..friendshipManager.setFriendshipListener(OnFriendshipListener(
        blackListAdd: (u) {},
        blackListDeleted: (u) {},
        friendApplicationListAccept: (u) {},
        friendApplicationListAdded: (u) {},
        friendApplicationListDeleted: (u) {},
        friendApplicationListReject: (u) {},
        friendInfoChanged: (u) {},
        friendListAdded: (u) {},
        friendListDeleted: (u) {},
      ))

      // Set up conversation listener
      ..conversationManager.setConversationListener(OnConversationListener(
        conversationChanged: (list) {},
        newConversation: (list) {},
        totalUnreadMsgCountChanged: (count) {},
        syncServerFailed: () {},
        syncServerFinish: () {},
        syncServerStart: () {},
      ))

      // Set up group listener
      ..groupManager.setGroupListener(OnGroupListener(
        applicationProcessed: (groupId, opUser, agreeOrReject, opReason) {},
        groupCreated: (groupId) {},
        groupInfoChanged: (groupId, info) {},
        memberEnter: (groupId, list) {},
        memberInvited: (groupId, opUser, list) {},
        memberKicked: (groupId, opUser, list) {},
        memberLeave: (groupId, info) {},
        receiveJoinApplication: (groupId, info, opReason) {},
      ));

4, Log in

 OpenIM.iMManager.login(uid: uid, token: token).then((value){
 	// login successful
 });

5,Get a list of conversations

 OpenIM.iMManager.conversationManager.getAllConversationList().then((list) {
 	// Return to the conversation list
 });

6,Get contact list

 OpenIM.iMManager.friendshipManager.getFriendList().then((list) {
   	// Return to friends list
 });

7,Get chat history

List<Message> chatMsgList = List.empty(growable: true);
  
/// Custom message listener, the arrival of a new message will trigger the onNewMessage method callback
class CustomAdvancedMsgListener extends AdvancedMsgListener {
  final ValueChanged<Message>? onNewMessage;

  CustomAdvancedMsgListener({
    this.onNewMessage,
  });

  @override
  void onRecvNewMessage(Message msg) {
    if (null != onNewMessage) onNewMessage!(msg);
  }
}
  • History news
  // If userID is not null and groupID is null, get a single chat message list
  // If the userID is null and the groupID is not null, get a group chat message list
  OpenIM.iMManager.messageManager.getHistoryMessageList(
          userID: uid,//User id
          startMsg: startMsg,//Last message, take chatMsgList[0]
          groupID: gid,//Group id
          count: 12,//Page Size
      )
      .then((list) => chatMsgList.addAll(list));
      
  • New news
// Create a message listener
// After entering the chat page, you need to listen for new messages and then render the UI
// Each chat window has a unique uid (user id) or gid (group id)
// Determine whether the received message belongs to the current window according to uid or gid
var msgListener = CustomAdvancedMsgListener(onNewMessage: (message) {
     // If the sender user id is equal to the user id of the current chat page,
     // or the group id is equal to the current group id of the current chat page
     if (message.sendID == uid || message.groupID == gid) {
        if (!chatMsgList.contains(message)) {
	 			 // New message in current chat page
          chatMsgList.add(event.message);
        }
     }
});

// Add message listener
OpenIM.iMManager.messageManager.addAdvancedMsgListener(msgListener);

// Remove message monitoring
// After adding a message listener, if the page disposes, please remove the listener
// OpenIM.iMManager.messageManager.removeAdvancedMsgListener(msgListener);

8,Send a message

// Create message
var message = await OpenIM.iMManager.messageManager.createTextMessage(
     text: 'I am the content of the message',
 );
// Send
OpenIM.iMManager.messageManager.sendMessage(
   message: message,
   onlineUserOnly: false,
   userID: uid, // Single chat value is not null
   groupID: gid, // The group chat value is not null
 ).then((v) {
   // Sent successfully
 }).catchError((e){
   // Failed to send
 });

9,Sign out

OpenIM.iMManager.logout();

OpenIM.iMManager

method description
initSDK Initialize SDK
unInitSDK
login Log in
logout Sign out
getLoginStatus Login status
getLoginUid Current user id
getLoginUserInfo Current user information
setSelfInfo Modify current user information
getUsersInfo Get user information by user id
forceReConn Force reconnection

OpenIM.iMManager.conversationManager

method description
setConversationListener Listener
getAllConversationList Get all conversation
getSingleConversation Get a single conversation
getMultipleConversation Get multiple conversation
deleteConversation Delete conversation
setConversationDraft Set conversation draftText
pinConversation Top conversation

OpenIM.iMManager.friendshipManager

method description
setFriendshipListener Listener
getFriendsInfo Get friend information
addFriend Add friends
getFriendApplicationList Get friend application list
getFriendList Get friends list
setFriendInfo Edit friend notes
addToBlackList Add to blacklist
getBlackList Get blacklist list
deleteFromBlackList Remove from blacklist
checkFriend Check friendship
deleteFromFriendList Remove friend
acceptFriendApplication Accept friend application
refuseFriendApplication Reject friend application

OpenIM.iMManager.messageManager

method description
addAdvancedMsgListener Add message listener
removeAdvancedMsgListener Remove message listener
setMsgSendProgressListener Message sending progress listener
sendMessage Send a message
getHistoryMessageList Get history news
revokeMessage Revoke message
deleteMessageFromLocalStorage Delete message
insertSingleMessageToLocalStorage Insert message
findMessages Query the message by id
markSingleMessageHasRead Mark single chat messages as read
markGroupMessageHasRead Mark group chat messages as read
markC2CMessageAsRead Mark c2c message as read
typingStatusUpdate Typing prompt
createTextMessage Create text message
createTextAtMessage Create @ message
createImageMessage Create picture message
createSoundMessage Create voice message
createVideoMessage Create video message
createFileMessage Create file message
createMergerMessage Create merge message
createForwardMessage Create a forwarded message
getTotalUnreadMsgCount Get unread message count

OpenIM.iMManager.groupManager

method description
setGroupListener Listener
inviteUserToGroup Invite into the group
kickGroupMember Remove group members
getGroupMembersInfo Get group member information
getGroupMemberList Get group members
getJoinedGroupList Get joined groups
isJoinedGroup Check you have joined the group
createGroup Create a group
setGroupInfo Set group information
getGroupsInfo Get group information
joinGroup Join group
quitGroup Exit group
transferGroupOwner Group permission transfer
getGroupApplicationList Get group application list
acceptGroupApplication Accept group invitation
refuseGroupApplication Decline group invitation
You might also like...

Decentralized SkyDB-based alternative to Twitter, YouTube and Instagram with a native iOS, Android and web app.

Decentralized SkyDB-based alternative to Twitter, YouTube and Instagram with a native iOS, Android and web app.

SkyFeed SkyFeed is a decentralized SkyDB-based alternative to Twitter, YouTube and Instagram with a native Android, web and (soon) iOS app. Use You ne

Oct 28, 2022

Paystack SDK for iOS. Accept Payments on iOS

Paystack iOS SDK The Paystack iOS SDK make it easy to collect your users' credit card details inside your iOS app. By charging the card immediately on

May 29, 2022

Best ever drawer in flutter for android and ios

Best ever drawer in flutter for android and ios

Drawer in Flutter Best ever drawer in flutter to make precious application. This flutter app is made just to demonstrate how you we can make an animat

Oct 16, 2022

A Flutter Starter Kit (Boilerplate) to kick-start your next Android and iOS app

A Flutter Starter Kit (Boilerplate) to kick-start your next Android and iOS app

Flutter Starter Kit (Boilerplate) using the BLoC Pattern A Flutter starter application that utilizes the BLoC Pattern. You can read more at this Mediu

Dec 28, 2022

A credit card scanner app made with flutter for both Android and IOS

credit_card_scanner A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

Oct 16, 2021

Number trivia Android and ios application using flutter clean architecture

demo_project A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Jun 9, 2022

Cross platform application for iOS and Android using Google's SDK Flutter.

Cross platform application for iOS and Android using Google's SDK Flutter.

scout Cross platform application for iOS and Android using Google's SDK Flutter. Launch screen for the application. The menu for selecting cookies. Cu

Nov 9, 2021

A mobile Truth or Dare game for iOS and Android application built using Flutter with CI/CD running on Codemagic.

A mobile Truth or Dare game for iOS and Android application built using Flutter with CI/CD running on Codemagic.

ToD Game A mobile Truth or Dare game for iOS and Android application built using Flutter with CI/CD running on Codemagic. Quick Start Prerequisites In

Dec 1, 2022

Cloth Shop it's an example using Flutter for Android and iOS.

Cloth Shop it's an example using Flutter for Android and iOS.

Cloth Shop - Flutter Cloth Shop it's an example using Flutter for Android and iOS. About This repository serves the source code for the Ecommers sampl

Oct 4, 2022
Owner
kostia7alania
->yourself;
kostia7alania
A Flutter plugin that supports Pangle SDK on Android and iOS.

Thanks for non-commercial open source development authorization by JetBrains. 穿山甲 Flutter SDK `pangle_flutter`是一款集成了字节跳动穿山甲 Android 和 iOS SDK的 Flutter

null 121 Dec 2, 2022
A robust Flutter plugin for making payments via Paystack Payment Gateway. Completely supports Android and iOS

?? Paystack Plugin for Flutter A Flutter plugin for making payments via Paystack Payment Gateway. Fully supports Android and iOS. ?? Installation To u

Wilberforce Uwadiegwu 165 Jan 4, 2023
A Flutter plugin for playing music on iOS and Android.

Stereo plugin for Flutter A Flutter plugin for playing music on iOS and Android. Features Play/pause Stop Duration / seek to position Load track from

2find 67 Sep 24, 2022
A flutter plugin for integrating razorpay payment gateway. Supports Android and iOS.

Flutter Razorpay Plugin A flutter plugin for razorpay integration for both android and ios. If you use this library in your app, please let me know an

Chetan Kaushik 28 Dec 13, 2022
A flutter IM plugin for android and ios

flutter_openim_sdk Download demo flutter_openim_widget A flutter IM plugin for android and ios. Getting Started 1,Add dependency in yaml flutter_op

kostia7alania 1 Dec 3, 2021
Video player-2.2.10 - A Flutter plugin for iOS, Android and Web for playing back video on a Widget surface

Video Player plugin for Flutter A Flutter plugin for iOS, Android and Web for pl

null 2 Sep 29, 2022
Caffodils - Download everything | Flutter app for Android and IOS. Download Video, Reels, Shorts, Music, Images, Files from Instagram, Facebook and Youtube

caffodils Caffodils - Download everything Flutter app for Android and IOS. Download Video, Reels, Shorts, Music, Images, Files from Instagram, Faceboo

Caffodils 11 Oct 24, 2022
Tesla car app using Flutter that works both android and iOS. Users can unlock any door, check battery status also control the air cooler temperature and check the psi of the tires.

Tesla App Tesla car app using Flutter that works both android and iOS. Users can unlock any door, check battery status also control the air cooler tem

null 12 Dec 18, 2022
A Flutter Twitch client for iOS and Android with BTTV, FFZ, and 7TV support

Frosty for Twitch A Twitch client for iOS and Android with BTTV, FFZ, and 7TV support. Built with Flutter. Features Browse followed streams, top strea

Tommy Chow 276 Jan 5, 2023