123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import 'dart:async';
- import 'package:flutter/services.dart';
- class FlutterPluginMipush {
- static const MethodChannel _channel = MethodChannel('flutter_plugin_mipush');
- static const EventChannel _event = EventChannel('flutter_plugin_mipush_event');
- static const EventChannel _state = EventChannel('flutter_plugin_mipush_state');
- static Stream<String> get stream => _event
- .receiveBroadcastStream()
- .map((event) => event as String);
- static Stream<String> get state => _state
- .receiveBroadcastStream()
- .map((event) => event as String);
- /// 初始化,如果没有appId或appKey,请登录小米开发者中心申请
- /// [appId] 应用appId
- /// [appKey] 应用appKey
- static Future<bool> init({
- required String appId,
- required String appKey,
- }) async {
- return await _channel.invokeMethod('init', {
- "appId": appId,
- "appKey": appKey,
- });
- }
- /// 设置别名
- /// [alias] 别名
- /// [category] 分类
- static Future<bool> setAlias({
- required String alias,
- required String category,
- }) async {
- return await _channel.invokeMethod('setAlias', {
- "alias": alias,
- "category": category,
- });
- }
- /// 撤销别名
- /// [alias] 别名
- /// [category] 分类
- static Future<void> unsetAlias({
- required String alias,
- required String category,
- }) async {
- return await _channel.invokeMethod('unsetAlias', {
- "alias": alias,
- "category": category,
- });
- }
- /// 获得所有别名
- static Future<List<String>> getAllAlias() async {
- return (await _channel.invokeMethod('getAllAlias')).cast<String>();
- }
- /// 设置用户账户
- /// [userAccount] 用户账户
- /// [category] 分类
- static Future<void> setUserAccount({
- required String userAccount,
- required String category,
- }) async {
- return await _channel.invokeMethod('setUserAccount', {
- "userAccount": userAccount,
- "category": category,
- });
- }
- /// 撤销设置用户账户
- /// [userAccount] 用户账户
- /// [category] 分类
- static Future<void> unsetUserAccount({
- required String userAccount,
- required String category,
- }) async {
- return await _channel.invokeMethod('unsetUserAccount', {
- "userAccount": userAccount,
- "category": category,
- });
- }
- /// 获得所有用户账户
- static Future<List<String>> getAllUserAccount() async {
- return (await _channel.invokeMethod('getAllUserAccount')).cast<String>();
- }
- /// 设置标签
- /// [topic] 标签
- /// [category] 分类
- static Future<void> subscribe({
- required String topic,
- required String category,
- }) async {
- return await _channel.invokeMethod('subscribe', {
- "topic": topic,
- "category": category,
- });
- }
- /// 撤销设置标签
- /// [topic] 标签
- /// [category] 分类
- static Future<void> unsubscribe({
- required String topic,
- required String category,
- }) async {
- return await _channel.invokeMethod('unsubscribe', {
- "topic": topic,
- "category": category,
- });
- }
- /// 获得所有标签
- static Future<List<String>> getAllTopic() async {
- return (await _channel.invokeMethod('getAllTopic')).cast<String>();
- }
- /// 获取客户端的 RegId
- static Future<String?> getRegId() async {
- return await _channel.invokeMethod('getRegId');
- }
- }
|