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