imsdk 0.0.14

  • Readme
  • Changelog
  • Example
  • Installing
  • 30

imsdk #

Flutter plugin for Tencent IM SDK.

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

0.0.13 #

  • Add - Send image,voice,emoji message support.
  • Add - Get self profile and other users profile support.
  • Add - Modify self profile support.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:imsdk/imsdk.dart';
import 'package:imsdk/message_element.dart';
import 'package:imsdk/conversation.dart';

void main() => runApp(new MyApp());

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

class _MyAppState extends State<MyApp> {
  final GlobalKey<ScaffoldState> _key = new GlobalKey();
  final TextEditingController _controllerAppId = new TextEditingController();
  final TextEditingController _controllerId = new TextEditingController();
  final TextEditingController _controllerSignature = new TextEditingController();
  String _platformVersion = 'Unknown';

  List<Conversation> _conversations = new List();
  @override
  void initState() {
    super.initState();
    initPlatformState();
    Imsdk.init();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Imsdk.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> children = new List();
    children.addAll(_conversations.map((conversation){
      return new InkWell(
        onTap: (){
          Navigator.of(context).push(new MaterialPageRoute(builder: (context){
            return new ChatPage(conversation);
          }));
        },
        child: new Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            new Text(conversation.type),
            new Text(conversation.id),
          ],
        ),
      );
    }).toList());
    children.add(new Column(
      children: <Widget>[
        new Text('Running on: $_platformVersion\n'),
        new Row(
          children: <Widget>[
            new Expanded(
              child: new TextFormField(
                decoration: InputDecoration(
                    hintText: 'Enter your appId'
                ),
                controller: _controllerAppId,
              )
            ),
            new MaterialButton(onPressed: (){
              print(_controllerAppId.text);
              Imsdk.initSdk(int.parse(_controllerAppId.text));
            },child: new Text('Init sdk'),)
          ],
        ),
        new TextFormField(
          decoration: InputDecoration(
              hintText: 'Enter your id'
          ),
          controller: _controllerId,
        ),
        new TextFormField(
          decoration: InputDecoration(
              hintText: 'Enter your signature'
          ),
          controller: _controllerSignature,
        ),
        new MaterialButton(onPressed: (){
          Imsdk.login(_controllerId.text, _controllerSignature.text).then((result){
            print('Login returned $result');
            _key.currentState.showSnackBar(new SnackBar(content: Text('Login returned $result')));
            if(result){
              Imsdk.getConversationList().then((result){
                setState(() {
                  _conversations = result;
                });
              });
            }
          });
        },child: new Text('Login'),)
      ],
    ));
    return new MaterialApp(
      home: new Scaffold(
        key: _key,
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new ListView(
          children: children,
        ),
      ),
    );
  }
}

class ChatPage extends StatefulWidget{
  final Conversation conversation;
  ChatPage(this.conversation);
  @override
  State<StatefulWidget> createState() {
    return new ChatPageState();
  }
}

class ChatPageState extends State<ChatPage>{
  final GlobalKey<ScaffoldState> _key = new GlobalKey();
  List<String> _textMessages = new List();
  String _message;
  @override
  void initState() {
    super.initState();
    Imsdk.onNewMessage = (message){
      print('---------------onNewMessage');
      print('elementCount:${message.count}');
      for(int i = 0;i < message.count;i ++){
        MessageElement e = message.elements[i];
        print('element $i type:${e.type}');
        print('text:${e.text}');
        _textMessages.add(e.text);
      }
      if(mounted){
        setState(() {

        });
      }
    };
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      key: _key,
      appBar: new AppBar(
        title: new Text('Chat with ${widget.conversation.id}'),
      ),
      body: new Stack(
        children: <Widget>[
          new Positioned.fill(
            child: new ListView(
              children: _textMessages.map((text){
                return new Text(text);
              }).toList(),
            ),
            bottom: 100.0,
          ),
          new Positioned(
            child: new Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                new TextFormField(
                  decoration: InputDecoration(
                      hintText: 'Enter your message'
                  ),
                  onSaved: (text){
                    _message = text;
                  },
                ),
                new MaterialButton(onPressed: (){

                  Imsdk.sendTextMessage(widget.conversation.type, widget.conversation.id, _message).then((result){
                    _key.currentState.showSnackBar(new SnackBar(content: Text('Send ${result ? 'succeed' : 'failed'}')));
                    if(result){
                      setState(() {
                        _textMessages.add(_message);
                      });
                    }
                  });
                },child: new Text('Send'),)
              ],
            ),
            bottom: 0.0,
            height: 100.0,
            left: 0.0,
            right: 0.0,
          )
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  imsdk: ^0.0.14

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

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:imsdk/imsdk.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:imsdk/imsdk.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:imsdk/imsdk.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:imsdk/imsdk.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [imsdk] that is in a package requiring null.

Health suggestions

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

Analysis of lib/imsdk.dart reported 1 hint:

line 14 col 35: This function has a return type of 'Future

Format lib/conversation.dart.

Run flutter format to format lib/conversation.dart.

Format lib/message.dart.

Run flutter format to format lib/message.dart.

Format lib/message_element.dart.

Run flutter format to format lib/message_element.dart.

Format lib/profile.dart.

Run flutter format to format lib/profile.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (json_annotation).

Package is getting outdated. (-62.19 points)

The package was last published 84 weeks ago.

The package description is too short. (-16 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.

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.0.0-dev.68.0 <3.0.0
flutter 0.0.0
json_annotation ^0.2.3 0.2.9+1 3.0.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
build_runner ^0.9.0
flutter_test
json_serializable ^0.5.4