youme 0.0.1

Flutter Android iOS

A new flutter plugin project.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:youme/youme.dart';

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

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

String appKey = "YOUMEDB869710BF23D30A189FF50537809438B3738C0D";
String appSecret = "2UJvOHVzgy63BMZRLGk6aj8/jsxsqfp50Js9uxyDJgTt0T1jWaBb2kqO7IT8ttsaaceAdjxsTyIB3B7bTZTjIr7XJeNRxfOTcH0A5qw+RuenWnq5UXyS6KDnnn3mbDskrL9XQ0WPcYs+XJDv2tgi8q/kCigqkm0DntvoXIrdjzMBAAE=";
String identifier = "100001";
String identifierOther = "100002";
String userId = "444455556";
String userIdTwo = "444455556";
String pwd = "123456";
String mChatRoomId = "12345";
class _MyAppState extends State<MyApp> {
  Youme _youme = new Youme();
  String _platformVersion = 'Unknown';

  StreamSubscription<dynamic> _messageStreamSubscription;

  @override
  void initState() {
    super.initState();
    initPlatformState();
    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 _youme.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;

    if (_messageStreamSubscription == null) {
      _messageStreamSubscription = _youme.onMessage.listen((dynamic onData) {
        print("我监听到数据了$onData");
      });
    }

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

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    //flutter 这里应该页面退出栈会调用,但是如果这个是根页面,日志是打不出来的。
    canCelListener();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: new Column(
            children: <Widget>[
              new Text('Running on: $_platformVersion\n'),
              RaisedButton(
                onPressed: () {
                  login();
                },
                child: Text('登录imsdk'),
              ),
              RaisedButton(
                onPressed: () {
                  logout();
                },
                child: Text('登出imsdk'),
              ),
              RaisedButton(
                onPressed: () {
                  postData();
                },
                child: Text('测试发送数据'),
              ),
              RaisedButton(
                onPressed: () {
                  canCelListener();
                },
                child: Text('取消监听'),
              ),
              RaisedButton(
                onPressed: () {
                  sendTextMsg();
                },
                child: Text('发送文本消息'),
              ),
              RaisedButton(
                onPressed: () {
                  sendImageMsg();
                },
                child: Text('发送图片消息'),
              ),
              RaisedButton(
                onPressed: () {
                  sendLocationMsg();
                },
                child: Text('发送位置消息'),
              ),
              RaisedButton(
                onPressed: () {
                  getMessages();
                },
                child: Text('拿到历史消息'),
              ),
              RaisedButton(
                onPressed: () {
                  getUserInfo();
                },
                child: Text('获取个人资料'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future<void> postData() async {
    try {
      var result = await _youme.postDataTest();
      print(result);
    } on PlatformException {
      print("listen  失败");
    }
  }

//  Future<void> login() async {
//    try {
//      var result = await _dim.imLogin(1400119955, "18681446372", "eJxlz11PwjAUgOH7-YpmtxjTj32AdwuCMIcGJkq9WWbXlkbsSul0avjvhkniEs-t856cnG8PAOA-ZPllyVjdaFe4T8N9cAV86F-8oTGqKkpXEFv9Q94aZXlRCsdthygMQwxhv1EV104JdS7snvTwUL0W3YXf7QBChGKI4n6iZIeLCR3Pl9dGrMUwj1iyqvSNXNMmmyU5HQ6mVjwumjs5truYbkcbTeR8m6RCRLssu0*pfVrepvmgbdhzFr1MP7gLZ-ir3qxkPGlZsB-1Tjr1xs-vBBBHJA5wT9*5PahadwGGKESYwNP43tH7ARZeXFI_");
////      var result = await _dim.postDataTest();
//      print(result);
//    } on PlatformException {
//      print("登录  失败");
//    }
//  }

  Future<void> sendTextMsg() async {
    try {
      var result = await _youme.sendTextMessages(userIdTwo, "haahah");
      print(result);
    } on PlatformException {
      print("发送消息失败");
    }
  }

  Future<void> sendImageMsg() async {
    try {
      var result = await _youme.sendImageMessages(identifierOther, "tyyhuiijkoi.png");
      print(result);
    } on PlatformException {
      print("发送图片消息失败");
    }
  }

  Future<void> sendLocationMsg() async {
    try {
      var result =
      await _youme.sendLocationMessages(identifierOther, 113.93, 22.54, "腾讯大厦");
      print(result);
    } on PlatformException {
      print("发送位置消息失败");
    }
  }
  Future<void> init() async {
    try {
      print(appKey);
      print(appSecret);
      var result = await _youme.init(appKey, appSecret);
      print(result);
    } on PlatformException {
      print("登录  失败");
    }
  }
  Future<void> login() async {
    try {

      var result = await _youme.login(userId, pwd);
      print(result);
    } on PlatformException {
      print("登录  失败");
    }
  }

  Future<void> logout() async {
    try {
      var result = await _youme.logout();
      print(result);
    } on PlatformException {
      print("登出  失败");
    }
  }

  Future<dynamic> getMessages() async {
    try {
      var result = await _youme.getMessages(
        identifier,
      );
      print(result);
    } on PlatformException {}
  }

  void canCelListener() {
    if (_messageStreamSubscription != null) {
      _messageStreamSubscription.cancel();
    }
  }

  void getUserInfo() async {
    try {
      List<String> users = List();
      users.add(identifier);
      var result = await _youme.getUsersProfile(users);
      print(result);
    } on PlatformException {
      print("获取个人资料失败");
    }
  }
}
0
likes
90
pub points
0%
popularity

A new flutter plugin project.

Homepage

Documentation

API reference

Uploader

elang88881@gmail.com

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on youme