78 lines
1.8 KiB
Dart
78 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
// 消息类型枚举
|
|
enum MessageType {
|
|
deviceStatus, // 设备状态
|
|
accessControl, // 通行权限
|
|
systemNotice, // 系统通知
|
|
}
|
|
|
|
// 消息数据模型
|
|
class MessageItem {
|
|
final MessageType type;
|
|
final String title;
|
|
final String subtitle;
|
|
final String time;
|
|
final bool hasRedDot;
|
|
|
|
MessageItem({
|
|
required this.type,
|
|
required this.title,
|
|
required this.subtitle,
|
|
required this.time,
|
|
required this.hasRedDot,
|
|
});
|
|
|
|
// 根据消息类型获取图标
|
|
IconData get icon {
|
|
switch (type) {
|
|
case MessageType.deviceStatus:
|
|
return Icons.devices;
|
|
case MessageType.accessControl:
|
|
return Icons.security;
|
|
case MessageType.systemNotice:
|
|
return Icons.notifications;
|
|
}
|
|
}
|
|
|
|
// 根据消息类型获取图标颜色
|
|
Color get iconColor {
|
|
switch (type) {
|
|
case MessageType.deviceStatus:
|
|
return const Color(0xFF4A90E2);
|
|
case MessageType.accessControl:
|
|
return const Color(0xFF4A90E2);
|
|
case MessageType.systemNotice:
|
|
return const Color(0xFFFF8C42);
|
|
}
|
|
}
|
|
|
|
// 根据消息类型获取图标背景色
|
|
Color get iconBgColor {
|
|
switch (type) {
|
|
case MessageType.deviceStatus:
|
|
return const Color(0xFFE8F4FD);
|
|
case MessageType.accessControl:
|
|
return const Color(0xFFE8F4FD);
|
|
case MessageType.systemNotice:
|
|
return const Color(0xFFFFF2E8);
|
|
}
|
|
}
|
|
|
|
// 创建副本,用于更新某些属性
|
|
MessageItem copyWith({
|
|
MessageType? type,
|
|
String? title,
|
|
String? subtitle,
|
|
String? time,
|
|
bool? hasRedDot,
|
|
}) {
|
|
return MessageItem(
|
|
type: type ?? this.type,
|
|
title: title ?? this.title,
|
|
subtitle: subtitle ?? this.subtitle,
|
|
time: time ?? this.time,
|
|
hasRedDot: hasRedDot ?? this.hasRedDot,
|
|
);
|
|
}
|
|
} |