mi_push 0.0.2 copy "mi_push: ^0.0.2" to clipboard
mi_push: ^0.0.2 copied to clipboard

PlatformAndroid

Lightweight Flutter plugin for xiaomi push integration. Simplifies push notifications on xiaomi devices, supporting token registration, message receiving, and callback handling.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:mi_push/mi_push.dart';
import 'package:permission_handler/permission_handler.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _pushPlugin = MiPush();
  final appId = '';
  final appKey = "";

  String _msg = '', _token = '';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('mi_push_example')),
        body: ListView(
          children: [
            Text(_msg),
            TextButton(
              onPressed: () {
                Permission.notification.request();
              },
              child: Text('request notification permission'),
            ),
            TextButton(
              onPressed: () {
                _pushPlugin.resumePush();
              },
              child: Text('resumePush'),
            ),
            TextButton(
              onPressed: () {
                _pushPlugin.pausePush();
              },
              child: Text('pausePush'),
            ),
            TextButton(
              onPressed: () {
                _pushPlugin.registerPush(appId, appKey);
              },
              child: Text('registerPush'),
            ),
            TextButton(
              onPressed: () {
                _pushPlugin.unregisterPush();
              },
              child: Text('unregisterPush'),
            ),
            TextButton(
              onPressed: () async {
                final token = await _pushPlugin.getRegId();
                _token = token;
                if (mounted) {
                  setState(() {
                    _msg = 'token:$token';
                  });
                }
              },
              child: Text('getRegId'),
            ),
            TextButton(
              onPressed: () {
                _pushPlugin.setPushTime(
                  startHour: 1,
                  startMin: 0,
                  endHour: 23,
                  endMin: 0,
                );
              },
              child: Text('setPushTime'),
            ),
            TextButton(
              onPressed: () {
                _pushPlugin.enablePush();
              },
              child: Text('enablePush'),
            ),
            TextButton(
              onPressed: () {
                _pushPlugin.disablePush();
              },
              child: Text('disablePush'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
160
points
154
downloads

Publisher

unverified uploader

Weekly Downloads

Lightweight Flutter plugin for xiaomi push integration. Simplifies push notifications on xiaomi devices, supporting token registration, message receiving, and callback handling.

Homepage
Repository (GitHub)
View/report issues

Topics

#mipush #xiaomi #xiaomipush

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on mi_push

Packages that implement mi_push