mi_push 0.0.2
mi_push: ^0.0.2 copied to clipboard
Lightweight Flutter plugin for xiaomi push integration. Simplifies push notifications on xiaomi devices, supporting token registration, message receiving, and callback handling.
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'),
),
],
),
),
);
}
}