notification_controller.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import 'package:calendar_view/utils/event_type.dart';
  2. import 'package:get/get.dart';
  3. import 'dart:math';
  4. class NotificationController extends GetxController {
  5. NotificationController();
  6. FEventHandler<SystemNotification> onReceiveNotification =
  7. FEventHandler<SystemNotification>();
  8. void handleReceiveNotification(SystemNotification notification) {
  9. onReceiveNotification.emit(this, notification);
  10. }
  11. /// 取0-5的随机整数
  12. int getRandomNumber() {
  13. return Random().nextInt(5);
  14. }
  15. /// 各种假消息列表
  16. List<SystemNotification> mockList = [
  17. SystemNotification(
  18. title: '系统通知',
  19. infoTitle: '会诊将在15分钟后开始,请及时参与!',
  20. infoItems: [
  21. NotificationInfoItem(
  22. title: '姓名',
  23. content: '陈圆润',
  24. ),
  25. NotificationInfoItem(
  26. title: '会诊时间',
  27. content: '2021-11-11 11:11:11',
  28. ),
  29. NotificationInfoItem(
  30. title: '会诊专家',
  31. content: 'Albert Einstein',
  32. ),
  33. ],
  34. type: NotificationType.notification,
  35. ),
  36. SystemNotification(
  37. title: '系统通知',
  38. infoTitle: '路人甲拒绝参加你的会诊!',
  39. infoItems: [
  40. NotificationInfoItem(
  41. title: '姓名',
  42. content: '陈圆润',
  43. ),
  44. NotificationInfoItem(
  45. title: '会诊时间',
  46. content: '2021-11-11 11:11:11',
  47. ),
  48. NotificationInfoItem(
  49. title: '拒绝原因',
  50. content: '阳了',
  51. ),
  52. ],
  53. type: NotificationType.error,
  54. ),
  55. SystemNotification(
  56. title: '系统通知',
  57. infoTitle: '路人甲拒绝了您的预约申请!',
  58. infoItems: [
  59. NotificationInfoItem(
  60. title: '拒绝原因',
  61. content: '没核酸检测报告',
  62. ),
  63. ],
  64. type: NotificationType.error,
  65. ),
  66. SystemNotification(
  67. title: '系统通知',
  68. infoTitle: '路人甲同意了您的预约申请!!',
  69. infoItems: [
  70. NotificationInfoItem(
  71. title: '姓名',
  72. content: '陈圆润',
  73. ),
  74. NotificationInfoItem(
  75. title: '会诊时间',
  76. content: '2021-11-11 11:11:11',
  77. ),
  78. NotificationInfoItem(
  79. title: '会诊专家',
  80. content: 'Albert Einstein',
  81. ),
  82. ],
  83. type: NotificationType.success,
  84. ),
  85. SystemNotification(
  86. title: '系统通知',
  87. infoTitle: '路人甲同意参加你的会诊!',
  88. infoItems: [
  89. NotificationInfoItem(
  90. title: '姓名',
  91. content: '陈圆润',
  92. ),
  93. NotificationInfoItem(
  94. title: '会诊时间',
  95. content: '2021-11-11 11:11:11',
  96. ),
  97. ],
  98. type: NotificationType.success,
  99. ),
  100. SystemNotification(
  101. title: '系统通知',
  102. infoTitle: '路人甲向您发来了会诊申请!',
  103. infoItems: [
  104. NotificationInfoItem(
  105. title: '姓名',
  106. content: '陈圆润',
  107. ),
  108. NotificationInfoItem(
  109. title: '会诊时间',
  110. content: '2021-11-11 11:11:11',
  111. ),
  112. NotificationInfoItem(
  113. title: '申请医院',
  114. content: '潘达医院',
  115. ),
  116. ],
  117. type: NotificationType.warning,
  118. ),
  119. ];
  120. /// 构造一个假消息
  121. void sendMockNotification() {
  122. handleReceiveNotification(mockList[getRandomNumber()]);
  123. }
  124. @override
  125. void onInit() {
  126. super.onInit();
  127. /// 注册通知接收器
  128. }
  129. }
  130. /// 系统通知
  131. class SystemNotification {
  132. SystemNotification({
  133. required this.title,
  134. required this.infoTitle,
  135. required this.infoItems,
  136. required this.type,
  137. this.callback,
  138. this.callbackButtonText,
  139. });
  140. final String title;
  141. final String infoTitle;
  142. final List<NotificationInfoItem> infoItems;
  143. final NotificationType type;
  144. final Function? callback;
  145. final String? callbackButtonText;
  146. }
  147. /// 通知信息字段
  148. class NotificationInfoItem {
  149. NotificationInfoItem({
  150. required this.title,
  151. required this.content,
  152. });
  153. final String title;
  154. final String content;
  155. }
  156. /// 通知类型
  157. enum NotificationType {
  158. /// 通知
  159. notification,
  160. /// 警告
  161. warning,
  162. /// 错误
  163. error,
  164. /// 成功
  165. success,
  166. }