flutter_lc_im 0.2.0+1

flutter_lc_im #

简单封装了LeanCloud的即时通讯功能(iOS/Android),给出了单聊和获取最近联系人列表。其中单聊功能使用的是原生实现,只是封装了一层跳转。而最近联系人列表则是使用Flutter重绘实现的。因此,最近联系人列表可以根据自己的需要定制界面。框架地址: flutter_lc_im 0.1.2

封装的功能有 #

1. 一对一聊天
1. 获取聊天列表
1. 根据聊天情况刷新聊天列表
1. 给出聊天列表上的未读消息数
1. 即时消息推送

安装方式 #

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

dependencies:
	flutter_lc_im: ^0.1.1
	  
flutter packages get

Flutter中的实现如下: #

    FlutterLcIm.register("appId", "appKey");
    FlutterLcIm.login("当前用户的userId");
    Map user = {'name':'jason1','user_id':"1",'avatar_url':"http://thirdqq.qlogo.cn/g?b=oidb&k=h22EA0NsicnjEqG4OEcqKyg&s=100"};
    Map peer = {'name':'jason2','user_id':"3",'avatar_url':"http://thirdqq.qlogo.cn/g?b=oidb&k=h22EA0NsicnjEqG4OEcqKyg&s=100"};
    //跳转到聊天界面
    FlutterLcIm.pushToConversationView(user,peer);
    
    //跳转到最近联系人列表
    FlutterLcIm.getRecentConversationUsers().then((res) {
      if (res != [] && res != null) {
        Conversations conversations = Conversations.fromJson(res);
                  print('conversations:${conversations.conversations}');

        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => ConversationListPage(conversations: conversations,)));
      }        

FlutterLcIm.pushToConversationView中第一个参数user指的是当前用户,第二个参数peer是聊天对象.

Getting Andriod Started #

第一步 AndroidManifest.xml加入以下配置 #

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
   android:theme="@style/LCIMKitTheme" >  //加入这个
	<activity
	xxxxxxxxx
	</activity>
</application>

第二步 Flutter项目中加入以下代码: #

    FlutterLcIm.register("appId", "Appkey"); //main.dart
    FlutterLcIm.login("当前用户的userId");    
    FlutterLcIm.pushToConversationView(user,peer);
    
    FlutterLcIm.getRecentConversationUsers().then((res) {
      if (res != [] && res != null) {
        Conversations conversations = Conversations.fromJson(res);
                  print('conversations:${conversations.conversations}');

        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => ConversationListPage(conversations: conversations,)));
      }

Getting iOS Started #

第一步 info.plist加入以下配置 #

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
</dict>
</plist>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<string>fetch</string>
	<string>remote-notification</string>
</array>
</plist>

第二步 AppDelegate.m中加入以下代码: #

#import <ChatKit/LCChatKit.h>
#import <UserNotifications/UserNotifications.h>

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [AVOSCloud handleRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    if (application.applicationState == UIApplicationStateActive) {
    } else {

        [[LCChatKit sharedInstance] didReceiveRemoteNotification:userInfo];
    }
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return YES;
}
/*!
 * Required for iOS 7+
 */
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    //TODO:处理远程推送内容
    NSLog(@"%@", userInfo);
    // Must be called when finished
    completionHandler(UIBackgroundFetchResultNewData);
}

#pragma mark - 实现注册APNs失败接口(可选)
///=============================================================================
/// @name 实现注册APNs失败接口(可选)
///=============================================================================

/**
 * also used in iOS10
 */
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"%s\n[无法注册远程提醒, 错误信息]\nline:%@\n-----\n%@\n\n", __func__, @(__LINE__), error);
}

第三步 Flutter项目中加入以下代码: #

    FlutterLcIm.register("appId", "Appkey"); //main.dart
    FlutterLcIm.login("当前用户的userId");    
    FlutterLcIm.pushToConversationView(user,peer);
    
    FlutterLcIm.getRecentConversationUsers().then((res) {
      if (res != [] && res != null) {
        Conversations conversations = Conversations.fromJson(res);
                  print('conversations:${conversations.conversations}');

        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => ConversationListPage(conversations: conversations,)));
      }

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/README.md

flutter_lc_im_example #

Demonstrates how to use the flutter_lc_im plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_lc_im: ^0.2.0+1

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]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

8 out of 8 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/flutter_lc_im.dart.

Run flutter format to format lib/flutter_lc_im.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.

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