flutter_mimc 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

Flutter_mimc v 0.1.0 #

[English] - 中文

thank@Xiaomi MIMC team's contribution #

Make IM easy

features #

  • Single chat
  • Ordinary group chat
  • Infinite group chat
  • Live stream(Not yet implemented)

Use needs #

useflutter_mimc,It is recommended to read firstXiaomi instant message cloud official document, This helps you to use flutter_mimc

Install flutter_mimc #

import #

pubspec.yaml Add the following dependency to the file:

  flutter_mimc: ^${latestVersion}

initialization #

Use flutter_mimc Before, need to perform initialization:

    import 'package:flutter_mimc/flutter_mimc.dart';

     // The first(String generated by server authentication)recommend
     String tokenString = http.get(); // '{"code":200,"message":"success","data":{}}';
     FlutterMimc flutterMimc1 =  FlutterMimc.stringTokenInit(
          debug: true,
     // The Second(Write sensitive data on the client)
      FlutterMimc flutterMimc2 = FlutterMimc.init(
           debug: true,
           appId: "xxxxxxxx",
           appKey: "xxxxxxxx",
           appSecret: "xxxxxxxx",
           appAccount: "xxxxxxxx"

Message body #

flutter_mimc Provide MIMCMessage model class

     MIMCMessage message = MIMCMessage();
     message.bizType = "bizType";      // Message type (developer custom)
     message.toAccount = "";           // Recipient account number (send single chat leave null)
     message.topicId = "";             // Specify the group ID to send (null when sending group chat)
     message.payload = "";             // Developer custom message body
     // Custom message body And Base64 encoding
     Map<String, dynamic> payloadMap = {
       "from_account": appAccount,
       "to_account": id,
       "biz_type": "text",
       "version": "0",
       "timestamp": DateTime.now().millisecondsSinceEpoch,
       "read": 0,
       "transfer_account": 0,
       "payload": content
     // base64 Handling custom messages
     message.payload = base64Encode(utf8.encode(json.encode(payloadMap)));
     // Send a single chat
     var pid = await flutterMimc.sendMessage(message);
     // Send a normal group chat
     var gid = await flutterMimc.sendGroupMsg(message);
     // Send unlimited group chat
     var gid = flutterMimc.sendGroupMsg(message, isUnlimitedGroup: true);


1.There may be some http api that does not implement the interface. Please first obtain the token through flutter_mim to call the interface. 2.Security verification is about to add this feature, the current sensitive information is fixed

example #

  FlutterMimc flutterMimc;
  final String appAccount = "100";         // My IM account
  String groupID = "21351198708203520";    // Ordinary group Account id
  String maxGroupID = "21360839299170304"; // Unlimited group Account id
  bool isOnline = false;
  List<Map<String, String>> logs = [];
  TextEditingController accountCtr = TextEditingController();
  TextEditingController contentCtr = TextEditingController();

  void initState() {
    // init FlutterMimc


  // init
  void initFlutterMimc() async{
    flutterMimc = FlutterMimc.init(
      debug: true,
      appId: "xxxxxxxx",
      appKey: "xxxxxxxx",
      appSecret: "xxxxxxxx",
      appAccount: appAccount
    addLog("init== init success ");

  // login
  void login() async{
    await flutterMimc.login();

  // add log
  addLog(String content){
      "date": DateTime.now().toIso8601String(),
      "content": content
    setState(() {});

  // logout
  void logout() async{
    await flutterMimc.logout();

  // send message
  void sendMessage(int type){
    String id = accountCtr.value.text;
    String content = contentCtr.value.text;

    if(id == null || id.isEmpty || content == null || content.isEmpty){
      _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("id or content Parameter error"), backgroundColor: Colors.pink,));

    MimcChatMessage messageRes = MimcChatMessage();
    MimcMessageBena messageBena = MimcMessageBena();
    messageRes.timestamp = DateTime.now().millisecondsSinceEpoch;
    messageRes.bizType = "bizType";
    messageRes.fromAccount = appAccount;
    messageBena.timestamp = DateTime.now().millisecondsSinceEpoch.toString();
    messageBena.payload = base64Encode(utf8.encode(content));
    messageBena.version  = 0;
    messageBena.msgId  = "msgId";
    messageRes.message = messageBena;
    if(type == 0){
      messageRes.toAccount = id;
      addLog("send to$id: $content");
    }else if(type == 1){
      messageRes.topicId = int.parse(id);
      addLog("Send a normal group message: $content");
      messageRes.topicId = int.parse(id);
      addLog("Send unlimited group messages: $content");
      flutterMimc.sendGroupMsg(messageRes, isUnlimitedGroup: true);

  // get token
  void getToken() async{
    String token = await flutterMimc.getToken();
    addLog("Get token successfully:$token");

  // Get current account
  void getAccount() async{
    String account = await flutterMimc.getAccount();
    addLog("Get current account successfully:$account");

  // Get current status
  void getStatus() async{
    bool isOnline =  await flutterMimc.isOnline();
    addLog("Get current status:${isOnline ? 'Online' :'Offline'}");

  // Create a group
  void createGroup() async{
    var res = await flutterMimc.createGroup("ios_group_name", appAccount);
      addLog("Create group failed:${res['message']}" );
      groupID = res['data']['topicInfo']['topicId'];
      addLog("Create group success:${res['data']}");
    accountCtr.text = groupID;
    setState(() { });

  // Query group
  void queryGroupInfo() async{
    var res = await flutterMimc.queryGroupInfo(groupID);
      addLog("Query group failed:${res['message']}" );
      addLog("Query group success:${res['data']}");

  // Query group information
  void queryGroupsOfAccount() async{
    var res = await flutterMimc.queryGroupsOfAccount();
      addLog("Querying group info failed:${res['message']}" );
      addLog("Querying group info success:${res['data']}");

  // Invite users to join the group
  void joinGroup() async{
    var res = await flutterMimc.joinGroup(groupID, "101,102,103");
      addLog("Invite users to join group failed:${res['message']}" );
      addLog("Invite users to join group success:${res['data']}");

  // Non-group master user quit group
  void quitGroup() async{
    var res = await flutterMimc.quitGroup(groupID);
      addLog("Non-group master user quit group failed:${res['message']}" );
      addLog("Non-group master user quit group success:${res['data']}");

  // Kicking members out of the group
  void kickGroup() async{
    var res = await flutterMimc.kickGroup(groupID, "101,102,103");
      addLog("Kicking members out of the group failed:${res['message']}");
      addLog("Kicking members out of the group success:${res['data']}");

  // Group owner update group information
  void updateGroup() async{
    var res = await flutterMimc.updateGroup(groupID, newOwnerAccount: "", newGroupName: "New group name" + groupID, newGroupBulletin: "New announcement");
      addLog("Group owner update group information failed:${res['message']}" );
      addLog("Group owner update group information success:${res['data']}");

  // Group destroyer
  void dismissGroup() async{
    var res = await flutterMimc.dismissGroup(groupID);
      addLog("Group destroyer failed:${res['message']}" );
      addLog("Group destroyer success:${res['data']}");

  // Pull single chat message record
  void pullP2PHistory() async{
    int thisTimer = DateTime.now().millisecondsSinceEpoch;
    String fromAccount = appAccount;
    String toAccount = "101";
    String utcFromTime = (thisTimer - 86400000).toString();
    String utcToTime = thisTimer.toString();
    var res = await flutterMimc.pullP2PHistory(
      toAccount: toAccount,
      fromAccount: fromAccount,
      utcFromTime: utcFromTime,
      utcToTime: utcToTime
      addLog("Pull single chat message record failed:${res['message']}" );
      addLog("Pull single chat message record success:${res['data']}");

  // Pull group chat message record
  void pullP2THistory() async{
    int thisTimer = DateTime.now().millisecondsSinceEpoch;
    String account = appAccount;
    String topicId = groupID;
    String utcFromTime = (thisTimer - 86400000).toString();
    String utcToTime = thisTimer.toString();
    var res = await flutterMimc.pullP2THistory(
      account: account,
      topicId: topicId,
      utcFromTime: utcFromTime,
      utcToTime: utcToTime
      addLog("Pull group chat message record failed:${res['message']}" );
      addLog("Pull group chat message record success:${res['data']}");

  // create unlimited group
  void createUnlimitedGroup() async{
    await flutterMimc.createUnlimitedGroup("unlimitedGroup");
    addLog("create unlimited group" );

  // join unlimited group
  void joinUnlimitedGroup() async{
    await flutterMimc.joinUnlimitedGroup("21395272047788032");
    addLog("join unlimited group$maxGroupID" );

  // quit unlimited group
  void quitUnlimitedGroup() async{
    await flutterMimc.quitUnlimitedGroup("21395272047788032");
    addLog("quit unlimited group$maxGroupID" );

  // dismiss unlimited group
  void dismissUnlimitedGroup() async{
    await flutterMimc.dismissUnlimitedGroup(maxGroupID);
    addLog("dismiss unlimited group$maxGroupID" );

  // Query unlimited group members
  void queryUnlimitedGroupMembers() async{
    var res = await flutterMimc.queryUnlimitedGroupMembers(maxGroupID);
    addLog("Query unlimited group members: $res" );

  // unlimited group I am in
  void queryUnlimitedGroups() async{
    var res = await flutterMimc.queryUnlimitedGroups();
    addLog("unlimited group I am in: $res" );

  // Query the number of unlimited group of online users
  void queryUnlimitedGroupOnlineUsers() async{
    var res =  await flutterMimc.queryUnlimitedGroupOnlineUsers(maxGroupID);
    addLog("online count data:$res" );

      // unlimited group Basic Information
  void queryUnlimitedGroupInfo() async{
    var res =  await flutterMimc.queryUnlimitedGroupInfo(maxGroupID);
    addLog("unlimited group Basic Information:$res" );

  // update unlimited group Basic Information
  void updateUnlimitedGroup() async{
    var res =  await flutterMimc.updateUnlimitedGroup(maxGroupID, newGroupName: "newGroupName");
    addLog("update unlimited group Basic Information:$res" );
  // Get recent contact list
    void getContact() async{
      var res =  await flutterMimc.getContact(isV2: true);
      addLog("Get recent contact list:$res" );
    // join Black List
    void setBlackList() async{
      var res =  await flutterMimc.setBlackList("200");
      addLog("join Black List:$res" );
    // cancel Black List
    void deleteBlackList() async{
      var res =  await flutterMimc.deleteBlackList("200");
      addLog("cancel Black List:$res" );
    // the account is in Black List?
    void hasBlackList() async{
      var res =  await flutterMimc.hasBlackList("200");
      addLog("the account is in Black List?:$res" );
    // join group Black List
    void setGroupBlackList() async{
      var res =  await flutterMimc.setGroupBlackList(blackTopicId: "21351198708203520", blackAccount: "102");
      addLog("join group Black List:$res" );
    // cancel group Black List
    void deleteGroupBlackList() async{
      var res =  await flutterMimc.deleteGroupBlackList(blackTopicId: "21351198708203520", blackAccount: "102");
      addLog("cancel group Black List:$res" );
    // the account is in group Black List?
    void hasGroupBlackList() async{
      var res =  await flutterMimc.hasGroupBlackList(blackTopicId: "21351198708203520", blackAccount: "102");
      addLog("the account is in group Black List?:$res" );

  // =========add Event Listener==============

    // Listener login status
      isOnline = status;
        addLog("$appAccount====status changed====Online");
        addLog("$appAccount====status changed====Offline");
      setState(() {});

    // Receive a single chat
    flutterMimc.addEventListenerHandleMessage().listen((MimcChatMessage resource){
      String content =utf8.decode(base64.decode(resource.message.payload));
      addLog("get${resource.fromAccount}message: $content");
      setState(() {});

    // Receiving group chat
    flutterMimc.addEventListenerHandleGroupMessage().listen((MimcChatMessage resource){
      String content =utf8.decode(base64.decode(resource.message.payload));
      addLog("get group${resource.topicId}message: $content");
      setState(() {});

    // Send message callback
    flutterMimc.addEventListenerServerAck().listen((MimcServeraAck ack){
      addLog("Send message callback==${ack.toJson()}");

    // Send a single chat timeout
    flutterMimc.addEventListenerSendMessageTimeout().listen((MimcChatMessage resource){
      addLog("Send a single chat timeout==${resource.toJson()}");

    // Send group chat timeout
    flutterMimc.addEventListenerSendGroupMessageTimeout().listen((MimcChatMessage resource){
      addLog("Send group chat timeout==${resource.toJson()}");

    // Send unlimited group chat timeout
    flutterMimc.addEventListenerSendUnlimitedGroupMessageTimeout().listen((MimcChatMessage resource){
      addLog("Send unlimited group chat timeout==${resource.toJson()}");

    // Create a unlimited group callback
    flutterMimc.addEventListenerHandleCreateUnlimitedGroup().listen((Map<dynamic, dynamic> res){
      addLog("Create a unlimited group callback==${res}");
      maxGroupID = (res['topicId'] as int).toString();

    // join unlimited group callback
    flutterMimc.addEventListenerHandleJoinUnlimitedGroup().listen((Map<dynamic, dynamic> res){
      addLog("join unlimited group callback==${res}");

    // quit unlimited group callback
    flutterMimc.addEventListenerHandleQuitUnlimitedGroup().listen((Map<dynamic, dynamic> res){
      addLog("quit unlimited group callback==${res}");

    // Dismiss unlimited group callback
    flutterMimc.addEventListenerHandleDismissUnlimitedGroup().listen((Map<dynamic, dynamic> res){
      addLog("Dismiss unlimited group callback==${res}");


Copyright 2019 keith

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements.  See the NOTICE file distributed with this work for
additional information regarding copyright ownership.  The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License.  You may obtain a copy of
the License at


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
License for the specific language governing permissions and limitations under
the License.

0.1.0 #

  • Add blacklist api
  • Add get contact list API
  • Add string token init func
  • Fix IOS import AFNetworking error

0.0.3+3 #

  • update api documentation

0.0.3+2 #

  • update api documentation

0.0.3+1 #

  • 1.Update README.md
  • 2.Fix BUG

0.0.3 #

  • Restore the message body, no restrictions, there is a misunderstanding before this has been fixed
  • Fix service ID returned by Android sending message is null
  • Update README.md

0.0.2 #

  • Delete the Android local JSON static library to avoid conflicts and compile

0.0.1 #

  • TODO: Describe initial release.


flutter_mimc_example #

Demonstrates how to use the flutter_mimc 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:

  flutter_mimc: ^0.1.0

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

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/flutter_mimc.dart.

Run flutter format to format lib/flutter_mimc.dart.


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