notification_card.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'package:calendar_view/notification_demo/notification_controller.dart';
  2. import 'package:flutter/material.dart';
  3. /// 消息卡片
  4. class NotificationCard extends StatelessWidget {
  5. const NotificationCard(
  6. {super.key, required this.notification, required this.onClose});
  7. final SystemNotification notification;
  8. final VoidCallback onClose;
  9. @override
  10. Widget build(BuildContext context) {
  11. return Container(
  12. decoration: BoxDecoration(
  13. color: Colors.white,
  14. borderRadius: BorderRadius.circular(8),
  15. boxShadow: const [
  16. BoxShadow(
  17. color: Colors.black12,
  18. blurRadius: 4,
  19. spreadRadius: 2,
  20. ),
  21. ],
  22. ),
  23. margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
  24. width: double.infinity,
  25. child: Column(
  26. crossAxisAlignment: CrossAxisAlignment.start,
  27. children: [
  28. _buildNotificationHeader(),
  29. Container(
  30. padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
  31. child: Text(
  32. notification.infoTitle,
  33. style: const TextStyle(
  34. color: Color.fromARGB(255, 30, 30, 30),
  35. fontSize: 16,
  36. fontWeight: FontWeight.w600,
  37. ),
  38. ),
  39. ),
  40. ..._buildInfoContents(notification.infoItems),
  41. const SizedBox(height: 12),
  42. ],
  43. ),
  44. );
  45. }
  46. Widget _buildNotificationHeader() {
  47. return Container(
  48. decoration: const BoxDecoration(
  49. border: Border(
  50. bottom: BorderSide(
  51. color: Colors.black12,
  52. width: 1,
  53. ),
  54. ),
  55. ),
  56. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
  57. child: Row(
  58. children: [
  59. _buildIconByType(notification.type),
  60. const SizedBox(width: 8),
  61. Text(notification.title),
  62. const Spacer(),
  63. InkWell(
  64. onTap: () {
  65. onClose();
  66. },
  67. child: const Icon(Icons.close)),
  68. ],
  69. ),
  70. );
  71. }
  72. Widget _buildIconByType(NotificationType type) {
  73. switch (type) {
  74. case NotificationType.notification:
  75. return const Icon(
  76. Icons.info_outline,
  77. color: Colors.blue,
  78. );
  79. case NotificationType.warning:
  80. return const Icon(
  81. Icons.warning_amber_outlined,
  82. color: Colors.orange,
  83. );
  84. case NotificationType.error:
  85. return const Icon(
  86. Icons.error_outline,
  87. color: Colors.red,
  88. );
  89. case NotificationType.success:
  90. return const Icon(
  91. Icons.check_circle_outline,
  92. color: Colors.green,
  93. );
  94. }
  95. }
  96. List<Widget> _buildInfoContents(List<NotificationInfoItem> infoContents) {
  97. return infoContents
  98. .map(
  99. (e) => Container(
  100. margin: const EdgeInsets.only(bottom: 8),
  101. padding: const EdgeInsets.symmetric(horizontal: 20),
  102. child: Row(
  103. children: [
  104. Expanded(
  105. flex: 1,
  106. child: Text(
  107. e.title,
  108. style: const TextStyle(
  109. color: Color.fromARGB(255, 40, 40, 40),
  110. fontSize: 14,
  111. ),
  112. ),
  113. ),
  114. Expanded(
  115. flex: 3,
  116. child: Text(
  117. e.content,
  118. style: const TextStyle(
  119. color: Color.fromARGB(255, 63, 63, 63),
  120. fontSize: 14,
  121. ),
  122. ),
  123. ),
  124. ],
  125. ),
  126. ),
  127. )
  128. .toList();
  129. }
  130. }