123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- import 'package:calendar_view/utils/event_type.dart';
- import 'package:get/get.dart';
- import 'dart:math';
- class NotificationController extends GetxController {
- NotificationController();
- FEventHandler<SystemNotification> onReceiveNotification =
- FEventHandler<SystemNotification>();
- void handleReceiveNotification(SystemNotification notification) {
- onReceiveNotification.emit(this, notification);
- }
- /// 取0-5的随机整数
- int getRandomNumber() {
- return Random().nextInt(5);
- }
- /// 各种假消息列表
- List<SystemNotification> mockList = [
- SystemNotification(
- title: '系统通知',
- infoTitle: '会诊将在15分钟后开始,请及时参与!',
- infoItems: [
- NotificationInfoItem(
- title: '姓名',
- content: '陈圆润',
- ),
- NotificationInfoItem(
- title: '会诊时间',
- content: '2021-11-11 11:11:11',
- ),
- NotificationInfoItem(
- title: '会诊专家',
- content: 'Albert Einstein',
- ),
- ],
- type: NotificationType.notification,
- ),
- SystemNotification(
- title: '系统通知',
- infoTitle: '路人甲拒绝参加你的会诊!',
- infoItems: [
- NotificationInfoItem(
- title: '姓名',
- content: '陈圆润',
- ),
- NotificationInfoItem(
- title: '会诊时间',
- content: '2021-11-11 11:11:11',
- ),
- NotificationInfoItem(
- title: '拒绝原因',
- content: '阳了',
- ),
- ],
- type: NotificationType.error,
- ),
- SystemNotification(
- title: '系统通知',
- infoTitle: '路人甲拒绝了您的预约申请!',
- infoItems: [
- NotificationInfoItem(
- title: '拒绝原因',
- content: '没核酸检测报告',
- ),
- ],
- type: NotificationType.error,
- ),
- SystemNotification(
- title: '系统通知',
- infoTitle: '路人甲同意了您的预约申请!!',
- infoItems: [
- NotificationInfoItem(
- title: '姓名',
- content: '陈圆润',
- ),
- NotificationInfoItem(
- title: '会诊时间',
- content: '2021-11-11 11:11:11',
- ),
- NotificationInfoItem(
- title: '会诊专家',
- content: 'Albert Einstein',
- ),
- ],
- type: NotificationType.success,
- ),
- SystemNotification(
- title: '系统通知',
- infoTitle: '路人甲同意参加你的会诊!',
- infoItems: [
- NotificationInfoItem(
- title: '姓名',
- content: '陈圆润',
- ),
- NotificationInfoItem(
- title: '会诊时间',
- content: '2021-11-11 11:11:11',
- ),
- ],
- type: NotificationType.success,
- ),
- SystemNotification(
- title: '系统通知',
- infoTitle: '路人甲向您发来了会诊申请!',
- infoItems: [
- NotificationInfoItem(
- title: '姓名',
- content: '陈圆润',
- ),
- NotificationInfoItem(
- title: '会诊时间',
- content: '2021-11-11 11:11:11',
- ),
- NotificationInfoItem(
- title: '申请医院',
- content: '潘达医院',
- ),
- ],
- type: NotificationType.warning,
- ),
- ];
- /// 构造一个假消息
- void sendMockNotification() {
- handleReceiveNotification(mockList[getRandomNumber()]);
- }
- @override
- void onInit() {
- super.onInit();
- /// 注册通知接收器
- }
- }
- /// 系统通知
- class SystemNotification {
- SystemNotification({
- required this.title,
- required this.infoTitle,
- required this.infoItems,
- required this.type,
- this.callback,
- this.callbackButtonText,
- });
- final String title;
- final String infoTitle;
- final List<NotificationInfoItem> infoItems;
- final NotificationType type;
- final Function? callback;
- final String? callbackButtonText;
- }
- /// 通知信息字段
- class NotificationInfoItem {
- NotificationInfoItem({
- required this.title,
- required this.content,
- });
- final String title;
- final String content;
- }
- /// 通知类型
- enum NotificationType {
- /// 通知
- notification,
- /// 警告
- warning,
- /// 错误
- error,
- /// 成功
- success,
- }
|