imsdk 0.0.12

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

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.12 #

  • Add - Add sender nick name and avatar to message.
  • Modify - sendTextMessage needs sender info now.

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.12

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';
  
Version Uploaded Documentation Archive
0.0.14 Nov 18, 2018 Go to the documentation of imsdk 0.0.14 Download imsdk 0.0.14 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

All 14 versions...

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]
74
Overall:
Weighted score of the above. [more]
45
Learn more about scoring.

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

  • Dart: 2.3.0
  • pana: 0.12.15
  • Flutter: 1.5.8

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-0.45 points)

53 out of 54 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/conversation.dart.

Run flutter format to format lib/conversation.dart.

Format lib/imsdk.dart.

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

Maintenance suggestions

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 2.2.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
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