{"id":24537448,"url":"https://github.com/paraself/leancloud-realtime-flutter","last_synced_at":"2025-03-16T01:22:47.902Z","repository":{"id":56833787,"uuid":"224143862","full_name":"paraself/leancloud-realtime-flutter","owner":"paraself","description":"LeanCloud实时消息组件在Flutter下的封装","archived":false,"fork":false,"pushed_at":"2019-12-31T11:13:19.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T14:12:40.173Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paraself.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-26T08:45:53.000Z","updated_at":"2023-01-16T07:28:49.000Z","dependencies_parsed_at":"2022-09-09T14:00:43.128Z","dependency_job_id":null,"html_url":"https://github.com/paraself/leancloud-realtime-flutter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paraself%2Fleancloud-realtime-flutter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paraself%2Fleancloud-realtime-flutter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paraself%2Fleancloud-realtime-flutter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paraself%2Fleancloud-realtime-flutter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paraself","download_url":"https://codeload.github.com/paraself/leancloud-realtime-flutter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243811073,"owners_count":20351649,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-22T14:12:44.976Z","updated_at":"2025-03-16T01:22:47.871Z","avatar_url":"https://github.com/paraself.png","language":"Dart","readme":"leancloud 的 即时消息 flutter 插件 leancloud_realtime_flutter\n当前仅支持了ios版本\n\n# 初始化\n```dart\n    LeancloudRealtime.Init(\n                id: \"your leancloud id\",\n                key: \"your leancloud id\",\n                serverURL: \"https://leancloud.cn\"\n      );\n```\n# 消息回调\n```dart\n    //收到消息的回调\n    LeancloudRealtime.OnMessageReceived = OnMessageReceived;\n  OnMessageReceived(AVIMMessage message){\n    print( message.text) ;\n    if(message is AVIMFileMessageBase){\n      print( message.url) ;\n    }\n  }\n```\n# 登入\n```dart\n    //用session token 登入\n    await LeancloudRealtime.become(\"ivdct9mt0c0sfg9nho23n1ox7\");\n```\n# 登出\n```dart\n    //用session token 登入\n    await LeancloudRealtime.close();\n```\n\n# 注册自定义消息\n```dart\n    //注册自定义消息\n    LeancloudRealtime.registerCustomMessage(1,()=\u003enew MyMessageType());\n\nclass MyMessageType extends AVIMMessage{\n  MyMessageType({String value}):super(mediaType:1){\n    customField = value;\n  }\n//设置自定义内容\n  void set customField (String value){\n    rawData[\"customField\"] = value;\n  }\n//读取自定义内容\n  String get customField{\n    return rawData[\"customField\"];\n  }\n}\n```\n\n# 创建对话\n```dart\n    // 第一个参数为除了自己以外,要拉入对话的人的id\n    var conversation = await LeancloudRealtime.CreateConversation([\"5ddb2c15844bb4008874ec3b\"],name: \"测试\");\n    print(conversation.conversationId);\n    // 发送文本消息\n    await conversation.SendTextMessageAsync('test 1');\n```\n\n# 发送文件消息\n```dart\n  TestSendImage()async {\n    //创建对话,默认 isUnique为真\n    print(\"TestSendImage\");\n    var imageMessage = new AVIMImageMessage(filePath:_imgPath.path );\n    var conversation = await LeancloudRealtime.CreateConversation([\"5ddb2c15844bb4008874ec3b\"],name: \"测试\");\n    print(conversation.conversationId);\n    // 发送文本消息 , progress为进度回调\n    await conversation.Send(imageMessage, progress: (f)=\u003e print(f));\n    print(\"TestSendImage Finish\");\n    print(imageMessage.toString());\n  }\n```\n其他类型消息,选择对应的文件消息类发送\n\n\n# 拉取消息\n```dart\n  TestConversation( List IDs)async {\n    //获取消息所在的 Conversation, 这里只拿返回的第一个做测试\n    var result = (await LeancloudRealtime.getConversations(IDs))[0];\n    //log出未读消息数量\n    print(result.conversationId+' unreadMessageCount '+result.unreadMessageCount.toString());\n    \n    //将消息标记为已读\n    result.read();\n\n    //获取历史消息\n    var messages = await result.QueryMessage();\n    // var messages = await result.QueryMessage(limit: 10,start: new MessageQueryEndpoint(sentTimestamp:1574627527681, messageID: \"6wXN4JBgoxqHA6SakWAnmz\" ));\n    // print(messages);\n    print(messages.map((f)=\u003e jsonEncode(f.rawData) ));\n  }\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparaself%2Fleancloud-realtime-flutter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparaself%2Fleancloud-realtime-flutter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparaself%2Fleancloud-realtime-flutter/lists"}