flutter_lc_im 1.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

flutter_lc_im #

More customizations, less code ! #

Introduction #

超级简单、轻量的Flutter聊天插件,支持ios和android两个平台。关键是免费!!!强势推荐一波LeanCloud!!! 这可能就是你要找的免费又好用的 flutter im。LeanCloud的使用传送门

Important #

全面升级flutter_lc_im,彻底剥离原生界面,让界面定制更容易!在0.2.5版本以前聊天界面还是用的原生代码,使得维护起来非常麻烦,尤其是对UI的修改,更是繁琐。为此,在1.0.0以后的版中去除原生界面的代码,使用flutter编写界面,让用户可以根据自己的业务绘制界面。同时example中已经提供了一套聊天的基础UI,可以直接使用或基于它进行修改。目前还处于Beta版,还在升级中,如需更多功能请Star支持。

Support #

  • [x] 一对一聊天

  • [x] 获取聊天列表(可自定义列表UI)

  • [x] 根据聊天情况刷新聊天列表

  • [x] 给出聊天列表上的未读消息数

  • [x] 发送图片消息

  • [x] 发送语音消息

  • [x] 发送视频消息

  • [x] 发送表情

  • [ ] 团组聊天

  • [x] 消息推送

  • [ ] ......

Flutter version #

v1.12.13+hotfix.8

Install #

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

dependencies:
	flutter_lc_im: ^1.1.2
	  
flutter packages get

Before Use #

在使用插件之前,你需要到leancloud官网上去注册一个账号,然后获得AppId、AppKey和REST API如下图所示:

Use: #

注册

FlutterLcIm.register("appId","appKey", "api",debug);

登陆

FlutterLcIm.login("clientId");

获取聊天列表

FlutterLcIm.queryHistoryConversations(_limit, _offset);  

创建单聊

FlutterLcIm.createConversation(peerId,limit);

获取聊天记录

  FlutterLcIm.queryHistoryConversationMessages()

发送文字消息

   FlutterLcIm.sendTextMessage();   

发送图片消息

   FlutterLcIm.sendImageMessage(); 

发送语音消息

   FlutterLcIm.sendVoiceMessage(); 

发送视频消息

   FlutterLcIm.sendVideoMessage(); 

关于推送

ios推送

ios端的推送在AppDelegate.m文件中设置,已给参考代码。主要步骤为三步

  1. 通过UNUserNotificationCenter注册
  2. 通过AVInstallation设置deviceToken
  3. 处理推送
android推送

android端目前只支持后台线程推送,暂不支持混合推送。推送代码很简单,只要在项目中的MainActivity中的resume函数中设置几行代码,如下所示:

    @Override
    protected void onResume() {
    super.onResume();

    // 获取推送消息数据
    String message = this.getIntent().getStringExtra("com.avoscloud.Data");
    String channel = this.getIntent().getStringExtra("com.avoscloud.Channel");

    if (message != null && FlutterLcImPlugin.notificationCallback != null){
      FlutterLcImPlugin.notificationCallback.success(message);
    }
}

More #

详细使用请看example中的代码

QQ技术交流: #

群聊号:853797155,欢迎交流问题和技术!

欢迎PR #

1.1.2 #

会话列表实现自动更新消息个数

1.1.1 #

android支持通知栏显示

修复ios端获取消息列表的问题

1.1.0 #

重构代码

支持视频

1.0.2 #

修复ios端podspec丢失问题

1.0.1 #

1.修复ios端消息放松的问题

2.新增消息列表的未读数显示

1.0.0 #

不再维护0.2.5以前的版本

全新的插件

0.2.5 #

1. android自定义FileProvider,避免与其他框架冲突

2. android修复小米等设备无法发图的问题

0.2.4+1 #

1.android加回FileProvider,否则无法发图

0.2.4 #

1.修复iOS端聊天界面无返回按钮的问题

2.android去掉FileProvider

0.2.3 #

1.重构了iOS端聊天消息记录逻辑,并修复推送bug

0.2.2 #

1.修复android端点击离线通知无法跳转到聊天界面的bug。

2.新增消息通知传递到原生的channel,实现点击通知跳转到指定页面。

3.根据lc的要求实现自定义api。

4.重构了iOS端消息通知的逻辑,便于用户获取通知消息。

0.2.1 #

修复android端无法推送的问题,并重构了代码。

0.2.0+1 #

im升级compile sdk 为28.

0.2.0 #

升级到androix.

0.1.2+1 #

完善Android端的问题.

0.1.2 #

修复android会话为null的问题.

0.1.1 #

ios 新增了推送功能.

0.1.0 #

增加了最近联系人列表.

0.0.9 #

更改使用逻辑.

0.0.8 #

可用的第一个版本.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_lc_im/flutter_lc_im.dart';
import 'package:flutter_lc_im_example/model/user.dart';
import 'package:flutter_lc_im_example/page/conversation.dart';

import 'page/conversation_list.dart';

void main() => runApp(MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();

    FlutterLcIm.register("-gzGzoHsz",
        "xxx", "https://leancloud.xxx.com",false);
    FlutterLcIm.login("1",notification: true);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Lean Cloud Im Plugin example app'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            _buildChatViewBtn(),
            _buildConversationListView(context)
          ],
        ),
      ),
    );
  }

  Widget _buildChatViewBtn() {
    return RaisedButton(
      child: Text('跳转去聊天界面'),
      onPressed: () {
        ImUser currentUser = ImUser(
            uid: '1',
            username: '张三',
            avatarUrl:
                'http://thirdqq.qlogo.cn/g?b=oidb&k=h22EA0NsicnjEqG4OEcqKyg&s=100');
        ImUser toUser = ImUser(
            uid: '1050',
            username: '莉丝',
            avatarUrl:
                'http://thirdqq.qlogo.cn/g?b=oidb&k=h22EA0NsicnjEqG4OEcqKyg&s=100');

        Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => ImConversationPage(
                    currentUser: currentUser,
                    toUser: toUser,
                  )),
        );
      },
    );
  }

  Widget _buildConversationListView(BuildContext context) {
    return RaisedButton(
      child: Text('跳转去最近联系人列表'),
      onPressed: () async {
        // List<ImConversation> conversations = List();
        // ImConversation conversation1 = ImConversation(
        //     clientId: "6",
        //     peerName: '测试1',
        //     peerId: '1050',
        //     lastMessage: ImMessage(text: '你好的方式发顺丰'),
        //     lastMessageAt: '2020-2-27',
        //     unreadMessagesCount: 1,
        //     avatarUrl:
        //         'http://thirdqq.qlogo.cn/g?b=oidb&k=h22EA0NsicnjEqG4OEcqKyg&s=100');
        // ImConversation conversation2 = ImConversation(
        //     clientId: "6",
        //     peerName: '测试2',
        //     peerId: '1050',
        //     lastMessage: ImMessage(text: '你好的方式发顺丰'),
        //     lastMessageAt: '2020-2-27',
        //     unreadMessagesCount: 10,
        //     avatarUrl:
        //         'http://thirdqq.qlogo.cn/g?b=oidb&k=h22EA0NsicnjEqG4OEcqKyg&s=100');
        // conversations.add(conversation1);
        // conversations.add(conversation2);

        Navigator.push(
          context,
          MaterialPageRoute(builder: (context) => ImConversationListPage()),
        );
      },
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_lc_im: ^1.1.2

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:flutter_lc_im/flutter_lc_im.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
22
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/flutter_lc_im.dart. (-0.50 points)

Analysis of lib/flutter_lc_im.dart reported 1 hint:

line 2 col 8: Unused import: 'dart:typed_data'.

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.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test