xiao_mi_push_plugin 2.0.0 copy "xiao_mi_push_plugin: ^2.0.0" to clipboard
xiao_mi_push_plugin: ^2.0.0 copied to clipboard

PlatformAndroid

This plug-in is packaged based on the xiaomi Push SDK, providing common methods and listeners

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()),
      "getRegId": () async =>
          controller.text = "${(await (XiaoMiPushPlugin.getRegId())) ?? "失败"}",
    };

    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) => OutlinedButton(
                          onPressed: methods[key] as void Function()?,
                          child: Text(key),
                        ),
                      )
                      .toList(),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
25
downloads

Publisher

verified publisherhuic.top

Weekly Downloads

This plug-in is packaged based on the xiaomi Push SDK, providing common methods and listeners

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on xiao_mi_push_plugin