imsdk 0.0.13

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new59

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 - Add conversation type and id to message.

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,"Test Sender","Test Avatar","Test Receiver","Test Avatar").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.13

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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';
  
Version Uploaded Documentation Archive
0.0.13 Oct 19, 2018 Go to the documentation of imsdk 0.0.13 Download imsdk 0.0.13 archive
0.0.12 Oct 19, 2018 Go to the documentation of imsdk 0.0.12 Download imsdk 0.0.12 archive
0.0.11 Oct 19, 2018 Go to the documentation of imsdk 0.0.11 Download imsdk 0.0.11 archive
0.0.10 Oct 19, 2018 Go to the documentation of imsdk 0.0.10 Download imsdk 0.0.10 archive
0.0.9 Oct 19, 2018 Go to the documentation of imsdk 0.0.9 Download imsdk 0.0.9 archive
0.0.8 Oct 19, 2018 Go to the documentation of imsdk 0.0.8 Download imsdk 0.0.8 archive
0.0.7 Oct 19, 2018 Go to the documentation of imsdk 0.0.7 Download imsdk 0.0.7 archive
0.0.6 Oct 19, 2018 Go to the documentation of imsdk 0.0.6 Download imsdk 0.0.6 archive
0.0.5 Oct 19, 2018 Go to the documentation of imsdk 0.0.5 Download imsdk 0.0.5 archive
0.0.4 Oct 19, 2018 Go to the documentation of imsdk 0.0.4 Download imsdk 0.0.4 archive

All 13 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
30
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means 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 2.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
build_runner ^0.9.0
flutter_test
json_serializable ^0.5.4