feat: 实现日历提醒完整功能(操作执行、通知服务重构、归档)
- 新增 ReminderActionExecutor 处理取消/稍后提醒操作 - 新增 ReminderOutboxStore 本地存储待处理操作 - 重构 LocalNotificationService 支持聚合提醒和交互操作 - 新增 event_color_resolver 工具类统一颜色解析 - 新增 CalendarService.archiveEvent 归档方法 - 增强 ModelTracking 支持缓存命中、推理token和成本追踪 - 添加 qwen3.5-35b-a3b 模型配置 - 更新 AndroidManifest 全屏intent权限 - 补充相关单元测试和文档
This commit is contained in:
@@ -44,6 +44,14 @@ class CalendarService {
|
||||
return _api.update(event);
|
||||
}
|
||||
|
||||
Future<ScheduleItemModel?> archiveEvent(String id) async {
|
||||
final event = await getEventById(id);
|
||||
if (event == null) {
|
||||
return null;
|
||||
}
|
||||
return updateEvent(event.copyWith(status: ScheduleStatus.archived));
|
||||
}
|
||||
|
||||
Future<void> deleteEvent(String id) async {
|
||||
await _api.delete(id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
enum ReminderAction {
|
||||
cancel('cancel'),
|
||||
snooze10m('snooze_10m'),
|
||||
timeout30s('timeout_30s'),
|
||||
autoArchive('auto_archive');
|
||||
|
||||
const ReminderAction(this.value);
|
||||
|
||||
final String value;
|
||||
|
||||
static ReminderAction fromValue(String raw) {
|
||||
return ReminderAction.values.firstWhere(
|
||||
(item) => item.value == raw,
|
||||
orElse: () => ReminderAction.timeout30s,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
class ReminderPayload {
|
||||
final String eventId;
|
||||
final String title;
|
||||
final DateTime startAt;
|
||||
final DateTime? endAt;
|
||||
final String timezone;
|
||||
final String? location;
|
||||
final String? notes;
|
||||
final String? color;
|
||||
final ReminderPayloadMode mode;
|
||||
final List<String> aggregateIds;
|
||||
final int version;
|
||||
|
||||
const ReminderPayload({
|
||||
required this.eventId,
|
||||
required this.title,
|
||||
required this.startAt,
|
||||
required this.timezone,
|
||||
this.endAt,
|
||||
this.location,
|
||||
this.notes,
|
||||
this.color,
|
||||
this.mode = ReminderPayloadMode.single,
|
||||
this.aggregateIds = const [],
|
||||
this.version = 1,
|
||||
});
|
||||
|
||||
ReminderPayload copyWith({
|
||||
String? eventId,
|
||||
String? title,
|
||||
DateTime? startAt,
|
||||
DateTime? endAt,
|
||||
String? timezone,
|
||||
String? location,
|
||||
String? notes,
|
||||
String? color,
|
||||
ReminderPayloadMode? mode,
|
||||
List<String>? aggregateIds,
|
||||
int? version,
|
||||
}) {
|
||||
return ReminderPayload(
|
||||
eventId: eventId ?? this.eventId,
|
||||
title: title ?? this.title,
|
||||
startAt: startAt ?? this.startAt,
|
||||
endAt: endAt ?? this.endAt,
|
||||
timezone: timezone ?? this.timezone,
|
||||
location: location ?? this.location,
|
||||
notes: notes ?? this.notes,
|
||||
color: color ?? this.color,
|
||||
mode: mode ?? this.mode,
|
||||
aggregateIds: aggregateIds ?? this.aggregateIds,
|
||||
version: version ?? this.version,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'eventId': eventId,
|
||||
'title': title,
|
||||
'startAt': startAt.toIso8601String(),
|
||||
'endAt': endAt?.toIso8601String(),
|
||||
'timezone': timezone,
|
||||
'location': location,
|
||||
'notes': notes,
|
||||
'color': color,
|
||||
'mode': mode.value,
|
||||
'aggregateIds': aggregateIds,
|
||||
'version': version,
|
||||
};
|
||||
}
|
||||
|
||||
factory ReminderPayload.fromJson(Map<String, dynamic> json) {
|
||||
final eventId = (json['eventId'] as String?) ?? '';
|
||||
if (eventId.isEmpty) {
|
||||
throw const FormatException('eventId is required');
|
||||
}
|
||||
|
||||
final startAtRaw = json['startAt'] as String?;
|
||||
if (startAtRaw == null || startAtRaw.isEmpty) {
|
||||
throw const FormatException('startAt is required');
|
||||
}
|
||||
final parsedStartAt = DateTime.parse(startAtRaw);
|
||||
|
||||
final mode = ReminderPayloadMode.fromValue(
|
||||
(json['mode'] as String?) ?? 'single',
|
||||
);
|
||||
final aggregateIds = (json['aggregateIds'] as List<dynamic>? ?? const [])
|
||||
.map((item) => item.toString())
|
||||
.toList();
|
||||
if (mode == ReminderPayloadMode.aggregate && aggregateIds.length < 2) {
|
||||
throw const FormatException('aggregateIds must contain at least 2 items');
|
||||
}
|
||||
|
||||
return ReminderPayload(
|
||||
eventId: eventId,
|
||||
title: (json['title'] as String?) ?? '',
|
||||
startAt: parsedStartAt,
|
||||
endAt: json['endAt'] != null
|
||||
? DateTime.parse(json['endAt'] as String)
|
||||
: null,
|
||||
timezone: (json['timezone'] as String?) ?? 'UTC',
|
||||
location: json['location'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
color: json['color'] as String?,
|
||||
mode: mode,
|
||||
aggregateIds: aggregateIds,
|
||||
version: (json['version'] as int?) ?? 1,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) {
|
||||
return true;
|
||||
}
|
||||
return other is ReminderPayload &&
|
||||
other.eventId == eventId &&
|
||||
other.title == title &&
|
||||
other.startAt == startAt &&
|
||||
other.endAt == endAt &&
|
||||
other.timezone == timezone &&
|
||||
other.location == location &&
|
||||
other.notes == notes &&
|
||||
other.color == color &&
|
||||
other.mode == mode &&
|
||||
_listEquals(other.aggregateIds, aggregateIds) &&
|
||||
other.version == version;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
eventId,
|
||||
title,
|
||||
startAt,
|
||||
endAt,
|
||||
timezone,
|
||||
location,
|
||||
notes,
|
||||
color,
|
||||
mode,
|
||||
Object.hashAll(aggregateIds),
|
||||
version,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum ReminderPayloadMode {
|
||||
single('single'),
|
||||
aggregate('aggregate');
|
||||
|
||||
const ReminderPayloadMode(this.value);
|
||||
|
||||
final String value;
|
||||
|
||||
static ReminderPayloadMode fromValue(String raw) {
|
||||
return ReminderPayloadMode.values.firstWhere(
|
||||
(item) => item.value == raw,
|
||||
orElse: () => ReminderPayloadMode.single,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool _listEquals(List<String> left, List<String> right) {
|
||||
if (left.length != right.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < left.length; i++) {
|
||||
if (left[i] != right[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import 'dart:math';
|
||||
|
||||
import '../data/services/calendar_service.dart';
|
||||
import '../../../core/notifications/local_notification_service.dart';
|
||||
import 'models/reminder_action.dart';
|
||||
import 'models/reminder_payload.dart';
|
||||
import 'reminder_outbox_store.dart';
|
||||
|
||||
class ReminderActionExecutor {
|
||||
final CalendarService _calendarService;
|
||||
final LocalNotificationService _notificationService;
|
||||
final ReminderOutboxStore _outboxStore;
|
||||
final Random _random;
|
||||
|
||||
ReminderActionExecutor({
|
||||
required CalendarService calendarService,
|
||||
required LocalNotificationService notificationService,
|
||||
required ReminderOutboxStore outboxStore,
|
||||
Random? random,
|
||||
}) : _calendarService = calendarService,
|
||||
_notificationService = notificationService,
|
||||
_outboxStore = outboxStore,
|
||||
_random = random ?? Random();
|
||||
|
||||
Future<void> handleAction({
|
||||
required ReminderAction action,
|
||||
required ReminderPayload payload,
|
||||
}) async {
|
||||
final ids = payload.mode == ReminderPayloadMode.aggregate
|
||||
? payload.aggregateIds
|
||||
: <String>[payload.eventId];
|
||||
|
||||
if (action == ReminderAction.cancel) {
|
||||
for (final id in ids) {
|
||||
await _notificationService.cancelEventReminder(id);
|
||||
await _archiveEvent(id, ReminderAction.cancel);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == ReminderAction.snooze10m ||
|
||||
action == ReminderAction.timeout30s) {
|
||||
for (final id in ids) {
|
||||
await _snoozeEvent(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> replayPendingActions() async {
|
||||
final pending = await _outboxStore.listPending();
|
||||
for (final item in pending) {
|
||||
if (item.targetStatus != 'archived') {
|
||||
await _outboxStore.markDone(item.opId);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await _calendarService.archiveEvent(item.eventId);
|
||||
await _outboxStore.markDone(item.opId);
|
||||
} catch (error) {
|
||||
await _outboxStore.markRetry(item.opId, error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _snoozeEvent(String eventId) async {
|
||||
final event = await _calendarService.getEventById(eventId);
|
||||
if (event == null) {
|
||||
return;
|
||||
}
|
||||
final now = DateTime.now();
|
||||
final endAt = event.endAt;
|
||||
if (endAt != null && !now.isBefore(endAt)) {
|
||||
await _notificationService.cancelEventReminder(eventId);
|
||||
await _archiveEvent(eventId, ReminderAction.autoArchive);
|
||||
return;
|
||||
}
|
||||
|
||||
final nextAt = now.add(const Duration(minutes: 10));
|
||||
if (endAt != null && !nextAt.isBefore(endAt)) {
|
||||
await _notificationService.cancelEventReminder(eventId);
|
||||
await _archiveEvent(eventId, ReminderAction.autoArchive);
|
||||
return;
|
||||
}
|
||||
|
||||
await _notificationService.scheduleReminderAt(event, nextAt);
|
||||
}
|
||||
|
||||
Future<void> _archiveEvent(String eventId, ReminderAction action) async {
|
||||
final opId =
|
||||
'${DateTime.now().millisecondsSinceEpoch}-${_random.nextInt(1 << 32)}';
|
||||
final outboxItem = ReminderOutboxItem(
|
||||
opId: opId,
|
||||
eventId: eventId,
|
||||
action: action,
|
||||
targetStatus: 'archived',
|
||||
occurredAt: DateTime.now(),
|
||||
);
|
||||
await _outboxStore.enqueue(outboxItem);
|
||||
try {
|
||||
await _calendarService.archiveEvent(eventId);
|
||||
await _outboxStore.markDone(opId);
|
||||
} catch (error) {
|
||||
await _outboxStore.markRetry(opId, error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'models/reminder_action.dart';
|
||||
|
||||
class ReminderOutboxItem {
|
||||
final String opId;
|
||||
final String eventId;
|
||||
final ReminderAction action;
|
||||
final String? targetStatus;
|
||||
final DateTime occurredAt;
|
||||
final int retryCount;
|
||||
final DateTime? nextRetryAt;
|
||||
final ReminderOutboxState state;
|
||||
final String? lastError;
|
||||
|
||||
const ReminderOutboxItem({
|
||||
required this.opId,
|
||||
required this.eventId,
|
||||
required this.action,
|
||||
required this.occurredAt,
|
||||
this.targetStatus,
|
||||
this.retryCount = 0,
|
||||
this.nextRetryAt,
|
||||
this.state = ReminderOutboxState.pending,
|
||||
this.lastError,
|
||||
});
|
||||
|
||||
String get idempotencyBucket {
|
||||
final bucket =
|
||||
occurredAt.millisecondsSinceEpoch ~/
|
||||
const Duration(minutes: 1).inMilliseconds;
|
||||
return '$eventId|${action.value}|$bucket';
|
||||
}
|
||||
|
||||
ReminderOutboxItem copyWith({
|
||||
int? retryCount,
|
||||
DateTime? nextRetryAt,
|
||||
ReminderOutboxState? state,
|
||||
String? lastError,
|
||||
}) {
|
||||
return ReminderOutboxItem(
|
||||
opId: opId,
|
||||
eventId: eventId,
|
||||
action: action,
|
||||
targetStatus: targetStatus,
|
||||
occurredAt: occurredAt,
|
||||
retryCount: retryCount ?? this.retryCount,
|
||||
nextRetryAt: nextRetryAt ?? this.nextRetryAt,
|
||||
state: state ?? this.state,
|
||||
lastError: lastError ?? this.lastError,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'opId': opId,
|
||||
'eventId': eventId,
|
||||
'action': action.value,
|
||||
'targetStatus': targetStatus,
|
||||
'occurredAt': occurredAt.toIso8601String(),
|
||||
'retryCount': retryCount,
|
||||
'nextRetryAt': nextRetryAt?.toIso8601String(),
|
||||
'state': state.value,
|
||||
'lastError': lastError,
|
||||
};
|
||||
}
|
||||
|
||||
factory ReminderOutboxItem.fromJson(Map<String, dynamic> json) {
|
||||
return ReminderOutboxItem(
|
||||
opId: (json['opId'] as String?) ?? '',
|
||||
eventId: (json['eventId'] as String?) ?? '',
|
||||
action: ReminderAction.fromValue(
|
||||
(json['action'] as String?) ?? 'timeout_30s',
|
||||
),
|
||||
targetStatus: json['targetStatus'] as String?,
|
||||
occurredAt: DateTime.parse(json['occurredAt'] as String),
|
||||
retryCount: (json['retryCount'] as int?) ?? 0,
|
||||
nextRetryAt: json['nextRetryAt'] != null
|
||||
? DateTime.parse(json['nextRetryAt'] as String)
|
||||
: null,
|
||||
state: ReminderOutboxState.fromValue(
|
||||
(json['state'] as String?) ?? 'pending',
|
||||
),
|
||||
lastError: json['lastError'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum ReminderOutboxState {
|
||||
pending('pending'),
|
||||
done('done'),
|
||||
dead('dead');
|
||||
|
||||
const ReminderOutboxState(this.value);
|
||||
final String value;
|
||||
|
||||
static ReminderOutboxState fromValue(String raw) {
|
||||
return ReminderOutboxState.values.firstWhere(
|
||||
(item) => item.value == raw,
|
||||
orElse: () => ReminderOutboxState.pending,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ReminderOutboxStore {
|
||||
static const String _key = 'calendar_reminder_outbox_v1';
|
||||
final SharedPreferences _prefs;
|
||||
|
||||
ReminderOutboxStore(this._prefs);
|
||||
|
||||
Future<void> enqueue(ReminderOutboxItem item) async {
|
||||
final current = await _readAll();
|
||||
final duplicated = current.any(
|
||||
(existing) =>
|
||||
existing.state == ReminderOutboxState.pending &&
|
||||
existing.idempotencyBucket == item.idempotencyBucket,
|
||||
);
|
||||
if (duplicated) {
|
||||
return;
|
||||
}
|
||||
current.add(item);
|
||||
await _writeAll(current);
|
||||
}
|
||||
|
||||
Future<List<ReminderOutboxItem>> listPending() async {
|
||||
final all = await _readAll();
|
||||
final now = DateTime.now();
|
||||
return all
|
||||
.where((item) => item.state == ReminderOutboxState.pending)
|
||||
.where(
|
||||
(item) => item.nextRetryAt == null || !item.nextRetryAt!.isAfter(now),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> markDone(String opId) async {
|
||||
final all = await _readAll();
|
||||
final updated = all
|
||||
.map(
|
||||
(item) => item.opId == opId
|
||||
? item.copyWith(
|
||||
state: ReminderOutboxState.done,
|
||||
nextRetryAt: null,
|
||||
)
|
||||
: item,
|
||||
)
|
||||
.toList();
|
||||
await _writeAll(updated);
|
||||
}
|
||||
|
||||
Future<void> markRetry(String opId, String error) async {
|
||||
final all = await _readAll();
|
||||
final updated = all.map((item) {
|
||||
if (item.opId != opId) {
|
||||
return item;
|
||||
}
|
||||
final nextRetryCount = item.retryCount + 1;
|
||||
if (nextRetryCount >= 8) {
|
||||
return item.copyWith(
|
||||
retryCount: nextRetryCount,
|
||||
state: ReminderOutboxState.dead,
|
||||
lastError: error,
|
||||
nextRetryAt: null,
|
||||
);
|
||||
}
|
||||
final delayMinutes = nextRetryCount == 1 ? 0 : 1 << (nextRetryCount - 1);
|
||||
return item.copyWith(
|
||||
retryCount: nextRetryCount,
|
||||
lastError: error,
|
||||
nextRetryAt: DateTime.now().add(Duration(minutes: delayMinutes)),
|
||||
);
|
||||
}).toList();
|
||||
await _writeAll(updated);
|
||||
}
|
||||
|
||||
Future<List<ReminderOutboxItem>> _readAll() async {
|
||||
try {
|
||||
final raw = _prefs.getString(_key);
|
||||
if (raw == null || raw.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
final list = jsonDecode(raw) as List<dynamic>;
|
||||
return list
|
||||
.whereType<Map>()
|
||||
.map(
|
||||
(item) =>
|
||||
ReminderOutboxItem.fromJson(Map<String, dynamic>.from(item)),
|
||||
)
|
||||
.toList();
|
||||
} catch (_) {
|
||||
await _prefs.remove(_key);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _writeAll(List<ReminderOutboxItem> items) async {
|
||||
final raw = jsonEncode(items.map((item) => item.toJson()).toList());
|
||||
await _prefs.setString(_key, raw);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import '../data/models/schedule_item_model.dart';
|
||||
|
||||
class ReminderOverlapGroup {
|
||||
final DateTime fireAt;
|
||||
final List<ScheduleItemModel> events;
|
||||
|
||||
const ReminderOverlapGroup({required this.fireAt, required this.events});
|
||||
|
||||
bool get isAggregate => events.length > 1;
|
||||
}
|
||||
|
||||
class ReminderOverlapPolicy {
|
||||
const ReminderOverlapPolicy();
|
||||
|
||||
List<ReminderOverlapGroup> groupByMinute(
|
||||
Iterable<ScheduleItemModel> events, {
|
||||
required DateTime now,
|
||||
}) {
|
||||
final buckets = <String, List<ScheduleItemModel>>{};
|
||||
final minuteToFireAt = <String, DateTime>{};
|
||||
|
||||
for (final event in events) {
|
||||
final fireAt = resolveFirstFireAt(event, now: now);
|
||||
if (fireAt == null) {
|
||||
continue;
|
||||
}
|
||||
final minute = DateTime(
|
||||
fireAt.year,
|
||||
fireAt.month,
|
||||
fireAt.day,
|
||||
fireAt.hour,
|
||||
fireAt.minute,
|
||||
);
|
||||
final key = minute.toIso8601String();
|
||||
buckets.putIfAbsent(key, () => <ScheduleItemModel>[]).add(event);
|
||||
minuteToFireAt[key] = minuteToFireAt[key] ?? fireAt;
|
||||
}
|
||||
|
||||
final groups = buckets.entries
|
||||
.map(
|
||||
(entry) => ReminderOverlapGroup(
|
||||
fireAt: minuteToFireAt[entry.key]!,
|
||||
events: entry.value,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
groups.sort((left, right) => left.fireAt.compareTo(right.fireAt));
|
||||
return groups;
|
||||
}
|
||||
|
||||
DateTime? resolveFirstFireAt(
|
||||
ScheduleItemModel event, {
|
||||
required DateTime now,
|
||||
}) {
|
||||
if (event.status != ScheduleStatus.active) {
|
||||
return null;
|
||||
}
|
||||
final reminderMinutes = event.metadata?.reminderMinutes;
|
||||
if (reminderMinutes == null) {
|
||||
return null;
|
||||
}
|
||||
final remindAt = event.startAt.subtract(Duration(minutes: reminderMinutes));
|
||||
final endAt = event.endAt;
|
||||
|
||||
if (endAt != null && !now.isBefore(endAt)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (now.isBefore(remindAt)) {
|
||||
return remindAt;
|
||||
}
|
||||
|
||||
if (endAt != null && now.isBefore(endAt)) {
|
||||
return now.add(const Duration(seconds: 5));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import '../../data/models/schedule_item_model.dart';
|
||||
import '../../data/services/calendar_service.dart';
|
||||
import '../calendar_state_manager.dart';
|
||||
import '../calendar_time_utils.dart';
|
||||
import '../utils/event_color_resolver.dart';
|
||||
import '../dayweek/day_event_layout_engine.dart';
|
||||
import '../dayweek/day_timeline_metrics.dart';
|
||||
import '../dayweek/day_view_scale.dart';
|
||||
@@ -614,7 +615,10 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen>
|
||||
required DayEventLayout layout,
|
||||
required double boardHeight,
|
||||
}) {
|
||||
final eventColor = _parseColor(layout.event.metadata?.color);
|
||||
final eventColor = resolveEventColor(
|
||||
status: layout.event.status,
|
||||
colorHex: layout.event.metadata?.color,
|
||||
);
|
||||
final isCompact = layout.visualHeight < 20;
|
||||
final tapHeight = layout.visualHeight < _minEventTapHeight
|
||||
? _minEventTapHeight
|
||||
@@ -687,17 +691,6 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Color _parseColor(String? hex) {
|
||||
if (hex == null || hex.isEmpty) {
|
||||
return AppColors.blue600;
|
||||
}
|
||||
try {
|
||||
return Color(int.parse(hex.replaceFirst('#', '0xFF')));
|
||||
} catch (_) {
|
||||
return AppColors.blue600;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildBottomDock() {
|
||||
return BottomDock(
|
||||
activeTab: DockTab.calendar,
|
||||
|
||||
@@ -10,6 +10,7 @@ import '../../../../shared/widgets/detail_header_action_menu.dart';
|
||||
import '../../../../shared/widgets/destructive_action_sheet.dart';
|
||||
import '../../data/services/calendar_service.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
import '../utils/event_color_resolver.dart';
|
||||
import '../widgets/create_event_sheet.dart';
|
||||
import '../widgets/calendar_share_dialog.dart';
|
||||
|
||||
@@ -223,7 +224,7 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
_formatReminderText(event.metadata?.reminderMinutes),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildColorField(event.metadata?.color),
|
||||
_buildColorField(event),
|
||||
const SizedBox(height: 14),
|
||||
if (event.metadata?.location != null) ...[
|
||||
_buildDetailField('地点', event.metadata!.location!),
|
||||
@@ -275,7 +276,10 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
width: 4,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: _parseColor(event.metadata?.color),
|
||||
color: resolveEventColor(
|
||||
status: event.status,
|
||||
colorHex: event.metadata?.color,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
@@ -343,8 +347,11 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildColorField(String? colorHex) {
|
||||
final color = _parseColor(colorHex);
|
||||
Widget _buildColorField(ScheduleItemModel event) {
|
||||
final color = resolveEventColor(
|
||||
status: event.status,
|
||||
colorHex: event.metadata?.color,
|
||||
);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -400,15 +407,6 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Color _parseColor(String? hex) {
|
||||
if (hex == null || hex.isEmpty) return AppColors.blue600;
|
||||
try {
|
||||
return Color(int.parse(hex.replaceFirst('#', '0xFF')));
|
||||
} catch (_) {
|
||||
return AppColors.blue600;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInputContainer() {
|
||||
return Container(
|
||||
height: 80,
|
||||
|
||||
@@ -7,6 +7,7 @@ import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_pressable.dart';
|
||||
import '../calendar_state_manager.dart';
|
||||
import '../calendar_time_utils.dart';
|
||||
import '../utils/event_color_resolver.dart';
|
||||
import '../widgets/bottom_dock.dart';
|
||||
import '../widgets/create_event_sheet.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
@@ -360,7 +361,10 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen>
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...displayEvents.map((event) {
|
||||
final color = _parseColor(event.metadata?.color);
|
||||
final color = resolveEventColor(
|
||||
status: event.status,
|
||||
colorHex: event.metadata?.color,
|
||||
);
|
||||
return AppPressable(
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
onTap: () {
|
||||
@@ -415,15 +419,6 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Color _parseColor(String? hex) {
|
||||
if (hex == null || hex.isEmpty) return AppColors.blue600;
|
||||
try {
|
||||
return Color(int.parse(hex.replaceFirst('#', '0xFF')));
|
||||
} catch (_) {
|
||||
return AppColors.blue600;
|
||||
}
|
||||
}
|
||||
|
||||
void _showMonthPicker() {
|
||||
var selectedYear = _currentMonth.year;
|
||||
var selectedMonth = _currentMonth.month;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
|
||||
Color resolveEventColor({
|
||||
required ScheduleStatus status,
|
||||
required String? colorHex,
|
||||
}) {
|
||||
if (status == ScheduleStatus.archived) {
|
||||
return AppColors.slate400;
|
||||
}
|
||||
|
||||
if (colorHex == null || colorHex.isEmpty) {
|
||||
return AppColors.blue600;
|
||||
}
|
||||
|
||||
try {
|
||||
return Color(int.parse(colorHex.replaceFirst('#', '0xFF')));
|
||||
} catch (_) {
|
||||
return AppColors.blue600;
|
||||
}
|
||||
}
|
||||
@@ -669,9 +669,9 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
try {
|
||||
final notificationService = sl<LocalNotificationService>();
|
||||
await notificationService.upsertEventReminder(saved);
|
||||
} catch (e) {
|
||||
} catch (_) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '提醒创建失败:$e', type: ToastType.warning);
|
||||
Toast.show(context, '提醒创建失败,请检查通知权限', type: ToastType.warning);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user