xiao_mi_push_plugin 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

xiao_mi_push_plugin #

pub package

小米推送SDK Flutter插件
小米Push版本: v3.7.6
测试时请使用真机测试,模拟器将会出现 code = 10017, msg= 参数值非法 异常

使用要求 #

Flutter Version >= 1.12

如果出现 22022 错误,请确保已启用推送服务,启用步骤参考: https://support.rongcloud.cn/ks/NzE5

配置 #

混淆 #

无需额外配置,已内部打入混淆

权限 #

修改 AndroidManifest.xml 文件,增加

    <permission android:name="你的包名.permission.MIPUSH_RECEIVE"
                android:protectionLevel="signature"/>
    <uses-permission android:name="你的包名.permission.MIPUSH_RECEIVE"/>

使用 #

接口 #

| ---- | ---- | ---- | | init | 初始化 | { appId: APP_ID , appKey: APP_KEY } | setAlias | 设置别名 | { alias: 别名, category: 分类 } | unsetAlias | 撤销别名 | { alias: 别名, category: 分类 } | getAllAlias | 获得所有别名 | - | setUserAccount | 设置用户账户 | { userAccount: 账户, category: 分类 } | unsetUserAccount | 撤销设置用户账户 | { userAccount: 账户, category: 分类 } | getAllUserAccount | 获得所有账户 | - | subscribe | 设置标签 | { topic: 标签, category: 分类 } | unsubscribe | 撤销设置标签 | { topic: 标签, category: 分类 } | getAllTopic | 获得所有标签 | -

监听器 #

添加监听器:XiaoMiPushPlugin.addListener,移除监听器:XiaoMiPushPlugin.removeListener
监听器方法原形: typedef ListenerValue<P> = void Function(XiaoMiPushListenerTypeEnum type, P params);

| ---- | ---- | ---- | | NotificationMessageClicked | 接收服务器推送的通知消息,用户点击后触发 | MiPushMessageEntity | RequirePermissions | 当所需要的权限未获取到的时候会回调该接口 | List

1.0.0 #

完成基本接口以及监听器配置

example/lib/main.dart

import 'dart:convert';

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

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

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

class _MyAppState extends State<MyApp> {
  TextEditingController controller = TextEditingController();

  Map<String, Function> methods = {};

  @override
  void initState() {
    super.initState();
    this.methods = {
      "init": () => XiaoMiPushPlugin.init(
          appId: "2882303761518406102", appKey: "5981840633102"),
      "setAlias": () =>
          XiaoMiPushPlugin.setAlias(alias: "test", category: "test"),
      "unsetAlias": () =>
          XiaoMiPushPlugin.unsetAlias(alias: "test", category: "test"),
      "getAllAlias": () async =>
          controller.text = jsonEncode(await XiaoMiPushPlugin.getAllAlias()),
      "setUserAccount": () => XiaoMiPushPlugin.setUserAccount(
          userAccount: "test", category: "test"),
      "unsetUserAccount": () => XiaoMiPushPlugin.unsetUserAccount(
          userAccount: "test", category: "test"),
      "getAllUserAccount": () async => controller.text =
          jsonEncode(await XiaoMiPushPlugin.getAllUserAccount()),
      "subscribe": () =>
          XiaoMiPushPlugin.subscribe(topic: "test", category: "test"),
      "unsubscribe": () =>
          XiaoMiPushPlugin.unsubscribe(topic: "test", category: "test"),
      "getAllTopic": () async =>
          controller.text = jsonEncode(await XiaoMiPushPlugin.getAllTopic()),
    };

    XiaoMiPushPlugin.addListener(onXiaoMiPushListener);
  }

  @override
  void dispose() {
    super.dispose();
    XiaoMiPushPlugin.removeListener(onXiaoMiPushListener);
  }

  /// 小米推送监听器
  onXiaoMiPushListener(type, params) {
    controller.text = ""
        "======================\n"
        "Listener ${type.toString().split(".")[1]}:\n"
        "--------------------------------------------\n"
        "${jsonEncode(params)}\n"
        "======================";
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              TextField(
                controller: controller,
                maxLines: 10,
              ),
              Expanded(
                child: Wrap(
                  runSpacing: 10,
                  spacing: 10,
                  children: methods.keys
                      .map(
                        (key) => RaisedButton(
                          onPressed: methods[key],
                          child: Text(key),
                        ),
                      )
                      .toList(),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  xiao_mi_push_plugin: ^1.0.0

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:xiao_mi_push_plugin/xiao_mi_push_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
30
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:xiao_mi_push_plugin/xiao_mi_push_plugin.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:xiao_mi_push_plugin/xiao_mi_push_plugin.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:xiao_mi_push_plugin/xiao_mi_push_plugin.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:xiao_mi_push_plugin/xiao_mi_push_plugin.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • xiao_mi_push_plugin that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
json_serializable 3.3.0 3.3.0
Transitive dependencies
_fe_analyzer_shared 5.0.0
analyzer 0.39.13
args 1.6.0
async 2.4.2
build 1.3.0
build_config 0.4.2
charcode 1.1.3
checked_yaml 1.0.2
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
glob 1.2.0
html 0.14.0+3
js 0.6.2
json_annotation 3.0.1
logging 0.11.4
meta 1.1.8 1.2.2
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.0 1.9.2
pub_semver 1.4.4
pubspec_parse 0.1.5
sky_engine 0.0.99
source_gen 0.9.6
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
flutter_test