honor_push 0.0.1
honor_push: ^0.0.1 copied to clipboard
Lightweight Flutter plugin for honor push integration. Simplifies push notifications on honor devices, supporting token registration, message receiving, and callback handling.
import 'package:flutter/material.dart';
import 'package:honor_push/honor_push.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 _honorPushPlugin = HonorPush();
String _msg = '';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('honor_push_example'),
),
body: Center(
child: Column(
children: [
Text(_msg),
TextButton(
onPressed: () {
_honorPushPlugin.initialize();
},
child: Text('initialize')),
TextButton(
onPressed: () async {
final resp = await _honorPushPlugin.getToken();
if (mounted) {
if (null != resp.token) {
setState(() {
_msg = 'token:${resp.token!}';
});
} else if (null != resp.errCode) {
setState(() {
_msg = 'errCode:${resp.errCode!}';
});
}
}
},
child: Text('getToken')),
TextButton(
onPressed: () async {
final resp = await _honorPushPlugin.deleteToken();
if (mounted) {
if (resp.success) {
setState(() {
_msg = 'deleteToken:${resp.success}';
});
} else if (null != resp.errCode) {
setState(() {
_msg = 'deleteToken errCode:${resp.errCode!}';
});
}
}
},
child: Text('deleteToken')),
TextButton(
onPressed: () async {
final resp =
await _honorPushPlugin.getNotificationCenterStatus();
if (mounted) {
if (resp.success) {
setState(() {
_msg =
'getNotificationCenterStatus:${resp.success}';
});
} else if (null != resp.errCode) {
setState(() {
_msg =
'getNotificationCenterStatus errCode:${resp.errCode!}';
});
}
}
},
child: Text('getNotificationCenterStatus')),
TextButton(
onPressed: () async {
final resp =
await _honorPushPlugin.turnOnNotificationCenter();
if (mounted) {
if (resp.success) {
setState(() {
_msg = 'turnOnNotificationCenter:${resp.success}';
});
} else if (null != resp.errCode) {
setState(() {
_msg =
'turnOnNotificationCenter errCode:${resp.errCode!}';
});
}
}
},
child: Text('turnOnNotificationCenter')),
TextButton(
onPressed: () async {
final resp =
await _honorPushPlugin.turnOffNotificationCenter();
if (mounted) {
if (resp.success) {
setState(() {
_msg = 'turnOffNotificationCenter:${resp.success}';
});
} else if (null != resp.errCode) {
setState(() {
_msg =
'turnOffNotificationCenter errCode:${resp.errCode!}';
});
}
}
},
child: Text('turnOffNotificationCenter')),
],
),
)),
);
}
}