u_push_plugin 0.10.0 icon indicating copy to clipboard operation
u_push_plugin: ^0.10.0 copied to clipboard

友盟推送Plugin

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:u_push_plugin/u_push_plugin.dart';
import 'package:u_push_plugin/data.dart';

import 'test_message_data.dart';
//import 'package:u_push_plugin_example/test_message_data.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String deviceToken = "";
  String message = "";

  @override
  void initState() {
    super.initState();
    UPushPlugin.initMessageListener();
    UPushPlugin.initRegisterListener((value) {
      deviceToken = value.message;
      setState(() {});
    });
    UPushPlugin.initMessageResultListener((value) {
      MessageData(value);
      setState(() {
        message = MessageData(value).message;
      });
    });
    UPushPlugin.getCacheMessage().then((value) {
      if (value != null) {
        if (value.isNotEmpty) {
          setState(() {
            message = MessageData(value).message;
          });
        }
      }
    });
    UPushPlugin.initMessageReceiverListener((value) {
      message = value.toString();
      setState(() {});
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
//    String platformVersion;
//    if (!mounted) return;
//
//    setState(() {
//      _platformVersion = platformVersion;
//    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: <Widget>[
            Text(deviceToken),
            Text(message),
            FlatButton(
                onPressed: () async {
                  deviceToken = await UPushPlugin.getDeviceToken();
                  setState(() {});
                },
                child: Text("获取登录信息")),
            FlatButton(
                onPressed: () async {
                  var data = await UPushPlugin.getTags();
//                  setState(() {});
                },
                child: Text("获取签名")),
            FlatButton(
                onPressed: () async {
                  print("添加签名");
                  var data = await UPushPlugin.addTags(["1", "2", "3"]);
//                  print(data);
//                  setState(() {});
                },
                child: Text("添加标签")),
            FlatButton(
                onPressed: () async {
                  print("删除标签");
                  var data = await UPushPlugin.deleteTags(["1", "2", "3"]);
                  print(data);
//                  setState(() {});
                },
                child: Text("删除标签")),
            FlatButton(
                onPressed: () async {
                  print("添加别名");
                  var data = await UPushPlugin.addAlias("testPush", "yyt");
                  print(data);
//                  setState(() {});
                },
                child: Text("添加别名")),
            FlatButton(
                onPressed: () async {
                  print("设置别名");
                  var data = await UPushPlugin.setAlias("testPush", "yyt");
                  print(data);
//                  setState(() {});
                },
                child: Text("设置别名")),
            FlatButton(
                onPressed: () async {
                  print("删除别名");
                  var data = await UPushPlugin.deleteAlias("testPush", "yyt");
                  print(data);
//                  setState(() {});
                },
                child: Text("删除别名")),
            FlatButton(
                onPressed: () async {
                  print("开启原生");
                  UPushPlugin.UMSetLogEnabled(true);
//                  setState(() {});
                },
                child: Text("开启原生")),
            FlatButton(
                onPressed: () async {
                  print("关闭原生");
                  UPushPlugin.UMSetLogEnabled(false);
//                  setState(() {});
                },
                child: Text("关闭原生")),
            FlatButton(
                onPressed: () async {
                  print("开启flutter");
                  UPushPlugin.changeFlutterLog(true);
//                  setState(() {});
                },
                child: Text("开启flutter")),
            FlatButton(
                onPressed: () async {
                  print("关闭flutter");
                  UPushPlugin.changeFlutterLog(false);
//                  setState(() {});
                },
                child: Text("关闭flutter"))
          ],
        ),
      ),
    );
  }
}
0
likes
100
pub points
0%
popularity

Publisher

unverified uploader

友盟推送Plugin

Homepage

Documentation

API reference

License

Icon for licenses.Apache-2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on u_push_plugin