leancloud_realtime_flutter 0.0.7

  • Readme
  • Changelog
  • Installing
  • new31

leancloud 的 即时消息 flutter 插件 leancloud_realtime_flutter 当前仅支持了ios版本

初始化 #

    LeancloudRealtime.Init(
                id: "your leancloud id",
                key: "your leancloud id",
                serverURL: "https://leancloud.cn"
      );

消息回调 #

    //收到消息的回调
    LeancloudRealtime.OnMessageReceived = OnMessageReceived;
  OnMessageReceived(AVIMTypedMessage message){
    print( message.text) ;
    if(message is AVIMFileMessageBase){
      print( message.url) ;
    }
  }

登入 #

    //用session token 登入
    await LeancloudRealtime.become("ivdct9mt0c0sfg9nho23n1ox7");

登出 #

    //用session token 登入
    await LeancloudRealtime.close();

注册自定义消息 #

    //注册自定义消息
    LeancloudRealtime.registerCustomMessage(1,()=>new MyMessageType());

class MyMessageType extends AVIMMessage{
  MyMessageType({String value}):super(mediaType:1){
    customField = value;
  }
//设置自定义内容
  void set customField (String value){
    rawData["customField"] = value;
  }
//读取自定义内容
  String get customField{
    return rawData["customField"];
  }
}

创建对话 #

    // 第一个参数为除了自己以外,要拉入对话的人的id
    var conversation = await LeancloudRealtime.CreateConversation(["5ddb2c15844bb4008874ec3b"],name: "测试");
    print(conversation.conversationId);
    // 发送文本消息
    await conversation.SendTextMessageAsync('test 1');

发送文件消息 #

  TestSendImage()async {
    //创建对话,默认 isUnique为真
    print("TestSendImage");
    var imageMessage = new AVIMImageMessage(filePath:_imgPath.path );
    var conversation = await LeancloudRealtime.CreateConversation(["5ddb2c15844bb4008874ec3b"],name: "测试");
    print(conversation.conversationId);
    // 发送文本消息 , progress为进度回调
    await conversation.Send(imageMessage, progress: (f)=> print(f));
    print("TestSendImage Finish");
    print(imageMessage.toString());
  }

其他类型消息,选择对应的文件消息类发送

拉取消息 #

  TestConversation( List IDs)async {
    //获取消息所在的 Conversation, 这里只拿返回的第一个做测试
    var result = (await LeancloudRealtime.getConversations(IDs))[0];
    //log出未读消息数量
    print(result.conversationId+' unreadMessageCount '+result.unreadMessageCount.toString());
    
    //将消息标记为已读
    result.read();

    //获取历史消息
    var messages = await result.QueryMessage();
    // var messages = await result.QueryMessage(limit: 10,start: new MessageQueryEndpoint(sentTimestamp:1574627527681, messageID: "6wXN4JBgoxqHA6SakWAnmz" ));
    // print(messages);
    print(messages.map((f)=> jsonEncode(f.rawData) ));
  }

0.0.7 #

  • TODO: Describe initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  leancloud_realtime_flutter: ^0.0.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:leancloud_realtime_flutter/AVFile.dart';
import 'package:leancloud_realtime_flutter/AVIMConversation.dart';
import 'package:leancloud_realtime_flutter/AVIMMessageMediaType.dart';
import 'package:leancloud_realtime_flutter/LeancloudRealtime.dart';
import 'package:leancloud_realtime_flutter/Message.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
64
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
31
Learn more about scoring.

We analyzed this package on Dec 5, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/AVIMConversation.dart. (-19.39 points)

Analysis of lib/AVIMConversation.dart reported 43 hints, including:

line 23 col 3: Prefer using /// for doc comments.

line 28 col 3: Prefer using /// for doc comments.

line 33 col 3: Prefer using /// for doc comments.

line 48 col 3: Prefer using /// for doc comments.

line 53 col 3: Prefer using /// for doc comments.

Fix lib/LeancloudRealtime.dart. (-10.44 points)

Analysis of lib/LeancloudRealtime.dart reported 22 hints, including:

line 17 col 22: Name non-constant identifiers using lowerCamelCase.

line 22 col 35: The exception variable 'error' isn't used, so the 'catch' clause can be removed.

line 57 col 27: Name non-constant identifiers using lowerCamelCase.

line 66 col 27: Name non-constant identifiers using lowerCamelCase.

line 76 col 10: This function has a return type of 'Future', but doesn't end with a return statement.

Fix lib/AVIMMessageMediaType.dart. (-6.78 points)

Analysis of lib/AVIMMessageMediaType.dart reported 14 hints, including:

line 2 col 3: Prefer using /// for doc comments.

line 5 col 20: Name non-constant identifiers using lowerCamelCase.

line 6 col 3: Prefer using /// for doc comments.

line 9 col 20: Name non-constant identifiers using lowerCamelCase.

line 10 col 3: Prefer using /// for doc comments.

Fix lib/Message.dart. (-5.36 points)

Analysis of lib/Message.dart reported 11 hints, including:

line 52 col 3: Prefer using /// for doc comments.

line 56 col 3: Prefer using /// for doc comments.

line 60 col 3: Prefer using /// for doc comments.

line 97 col 3: Prefer using /// for doc comments.

line 102 col 3: Prefer using /// for doc comments.

Format lib/AVFile.dart.

Run flutter format to format lib/AVFile.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and leancloud_realtime_flutter.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test