FlutterNetEase cloud letter SDK

nim_flutter

For FlutterNetEase cloud letter SDK

Current function

  • log in
  • auto login
  • sign out
  • Kick out
  • Get a list of recent conversations
  • Delete a list of recent conversations
  • Open new conversation
  • Close open session
  • Get conversation message
  • Send and receive text, pictures, video, audio messages
  • Send and receive custom messages
  • Mark audio read
  • Call NIMSDKability to record and send voice messages
  • Audio, video and voice (under development)
  • Chat room (under development)
  • Interactive live broadcast (under development)
Group chat is not supported

Some examples

initialization

Before use, first initialize:

void  main () async {
   FlutterNIM (). init (
    appKey :  "123456" ,
    apnsCername :  "ABCDEFG" , // iOS production environment certificate name 
    apnsCernameDevelop :  "ABCDEFG" , // iOS test environment certificate name 
    imAccount :  "123456" ,
    imToken :  "123456" ,
  );

  runApp ( MyApp ());
}

Due to SDK limitations, the Android platform still needs to be initialized in Application, you can refer to the following code:

public  class  MyApplication  extends  FlutterApplication {
     @Override 
    public  void  onCreate () {
         super . onCreate();

        FlutterNIMPreferences . SetContext ( this );
         // SDK initialization (start background service, if user login information already exists, SDK will complete automatic login) 
        NIMClient . Init( this , FlutterNIMPreferences . GetLoginInfo (), buildSDKOptions());
    }

    // NetEase 
    Yunxin configuration (you can also use your own configuration here) private  SDKOptions  buildSDKOptions () {
         return  FlutterNIMSDKOptionConfig . GetSDKOptions( this , " 123456 " , buildMixPushConfig());
    }

    // NetEase 
    Yunxin third-party push configuration private  MixPushConfig  buildMixPushConfig () {

        MixPushConfig config =  new  MixPushConfig ();

        // Xiaomi pushes 
        config . xmAppId =  " 123456 " ;
        config . xmAppKey =  " 123456 " ;
        config . xmCertificateName =  " ABCDEFG " ;

        // Huawei pushes 
        config . HwCertificateName =  " ABCDEFG " ;
         ...

        return config;
    }
}

log in

bool isSuccess =  await  FlutterNIM (). login (imAccount, imToken);

sign out

FlutterNIM (). logout ();

Kick out

FlutterNIM ().kickReasonResponse. listen (( NIMKickReason reason) {
     // Handling the logic of being kicked offline 
});

List of recent conversations

Manually get the list of recent conversations:

FlutterNIM (). loadRecentSessions ();

Listening to recent conversations, manually calling to get the recent conversation list or changes in the recent conversation list (add, update, delete, mark read) will trigger this callback.

FlutterNIM ().recentSessionsResponse. listen ((recentSessions) {
     List < NIMSession > _recentSessions = recentSessions;

    // Here you can calculate the total unread of recent sessions 
    int unreadNum = recentSessions
        . map ((s) => s.unreadCount)
        . fold ( 0 , (curr, next) => curr + next);
    });

Delete a session (only delete the local cache, not the cloud record)

FlutterNIM (). deleteRecentSession (session.sessionId);

Conversation

Start a new conversation

bool isSuccess =  await  FlutterNIM (). startChat (session.sessionId);

Listen for conversation messages

FlutterNIM ().messagesResponse. listen ((messages) {
     List < NIMMessage > _messages = messages;

    // Find the remainder, if the result is equal to zero, there may be more data 
    int _remainder =  this ._messages.length %  20 ;
     bool _hasMoreData = remainder ==  0 ;
    });

When you exit the chat page, you need to close the session

FlutterNIM (). exitChat ();

send messages

// Send text message 
FlutterNIM (). sendText (content);

// Send image message 
FlutterNIM (). sendImage (file.path);

// Send video message 
FlutterNIM (). sendVideo (file.path);

The voice message calls the recording capability of the native Yunxin SDK

// Start recording 
FlutterNIM (). onStartRecording ();

// End the recording and automatically send a voice message 
FlutterNIM (). onStopRecording ();

// Cancel recording, will not send 
FlutterNIM (). onCancelRecording ();

Custom message

Put the custom message content Mapin:

    // Feel free to define 
    Map < String , dynamic > customObject = {
       "type" :  "Custom" ,
       "url" :  "xxx" ,
      ...
    };

    FlutterNIM (). sendCustomMessage (
      customObject,
      apnsContent :  "[A custom message has been sent]" ,
    );

The received custom message body JSONexists NIMMessagein the format of a string customMessageContent, and then parse it by yourself:

final customObjectMap = json. decode (customMessageContent);
 // Custom 
var model =  CustomModel . fromJson (customObjectMap);

This SDK refers to the following author’s work flutter_nim

Download Details:

Author: cls8428181

Source Code: https://github.com/cls8428181/nim_flutter

#flutter #dart #mobile-apps

FlutterNetEase cloud letter SDK
3.00 GEEK