Skip to main content

🚀 Using the Demo​

We strongly recommend you start by running the framework-specific sample DEMO we've prepared for you. This will not only give you a firsthand experience of OpenIMSDK's functionalities but will also assist you in swiftly identifying and resolving potential issues during the integration process.

Integration Steps​

1. Add Dependencies to yaml​

   flutter_openim_sdk: latest

2. Import the Package​

  import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';

3. Initialization​

final success = await OpenIM.iMManager.initSDK(
platform: 0, // Platform, refer to IMPlatform class,
apiAddr: "", // API address of the SDK.
wsAddr: "", // Web socket address of the SDK.
dataDir: "", // Data storage path. E.g., var apath =(await getApplicationDocumentsDirectory()).path
objectStorage: 'cos', // Image server, default is 'cos'
logLevel: 6, // Log level, default is 6
listener: OnConnectListener(
onConnectSuccess: () {
// Successfully connected to the server.
},
onConnecting: () {
// Connecting to the server, ideal for displaying a "Connecting" status on the UI.
},
onConnectFailed: (code, errorMsg) {
// Failed to connect to the server; you can notify the user that the current network connection is unavailable.
},
onUserSigExpired: () {
// The login ticket has expired. Please log in with a newly issued UserSig.
},
onKickedOffline: () {
// The current user has been kicked offline. You can prompt the user, "You have logged into this account on another device. Would you like to log in again?"
},
),
);

4. Set Listeners​

// Set listener
OpenIM.iMManager
//
..userManager.setUserListener(OnUserListener(
))
// Add message listener (remove when not in use)
..messageManager.setAdvancedMsgListener(OnAdvancedMsgListener(
))

// Set up message sending progress listener
..messageManager.setMsgSendProgressListener(OnMsgSendProgressListener(
))
..messageManager.setCustomBusinessListener(
)
// Set up friendship listener
..friendshipManager.setFriendshipListener(OnFriendshipListener(
))

// Set up conversation listener
..conversationManager.setConversationListener(OnConversationListener(
))

// Set up group listener
..groupManager.setGroupListener(OnGroupListener(
));

5. Login​

// Returns the profile of the currently logged-in user.
final userInfo = await OpenIM.iMManager.login(
userID: "", // userID comes from your business server.
token: "", // token needs to be exchanged from the OpenIM server by your business server using the secret.
);