123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import 'package:calendar_view/notification_demo/notification_controller.dart';
- import 'package:flutter/material.dart';
- /// 消息卡片
- class NotificationCard extends StatelessWidget {
- const NotificationCard(
- {super.key, required this.notification, required this.onClose});
- final SystemNotification notification;
- final VoidCallback onClose;
- @override
- Widget build(BuildContext context) {
- return Container(
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(8),
- boxShadow: const [
- BoxShadow(
- color: Colors.black12,
- blurRadius: 4,
- spreadRadius: 2,
- ),
- ],
- ),
- margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
- width: double.infinity,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildNotificationHeader(),
- Container(
- padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
- child: Text(
- notification.infoTitle,
- style: const TextStyle(
- color: Color.fromARGB(255, 30, 30, 30),
- fontSize: 16,
- fontWeight: FontWeight.w600,
- ),
- ),
- ),
- ..._buildInfoContents(notification.infoItems),
- const SizedBox(height: 12),
- ],
- ),
- );
- }
- Widget _buildNotificationHeader() {
- return Container(
- decoration: const BoxDecoration(
- border: Border(
- bottom: BorderSide(
- color: Colors.black12,
- width: 1,
- ),
- ),
- ),
- padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
- child: Row(
- children: [
- _buildIconByType(notification.type),
- const SizedBox(width: 8),
- Text(notification.title),
- const Spacer(),
- InkWell(
- onTap: () {
- onClose();
- },
- child: const Icon(Icons.close)),
- ],
- ),
- );
- }
- Widget _buildIconByType(NotificationType type) {
- switch (type) {
- case NotificationType.notification:
- return const Icon(
- Icons.info_outline,
- color: Colors.blue,
- );
- case NotificationType.warning:
- return const Icon(
- Icons.warning_amber_outlined,
- color: Colors.orange,
- );
- case NotificationType.error:
- return const Icon(
- Icons.error_outline,
- color: Colors.red,
- );
- case NotificationType.success:
- return const Icon(
- Icons.check_circle_outline,
- color: Colors.green,
- );
- }
- }
- List<Widget> _buildInfoContents(List<NotificationInfoItem> infoContents) {
- return infoContents
- .map(
- (e) => Container(
- margin: const EdgeInsets.only(bottom: 8),
- padding: const EdgeInsets.symmetric(horizontal: 20),
- child: Row(
- children: [
- Expanded(
- flex: 1,
- child: Text(
- e.title,
- style: const TextStyle(
- color: Color.fromARGB(255, 40, 40, 40),
- fontSize: 14,
- ),
- ),
- ),
- Expanded(
- flex: 3,
- child: Text(
- e.content,
- style: const TextStyle(
- color: Color.fromARGB(255, 63, 63, 63),
- fontSize: 14,
- ),
- ),
- ),
- ],
- ),
- ),
- )
- .toList();
- }
- }
|