feat: 增强日历功能并集成 AgentScope 代理服务
This commit is contained in:
@@ -24,11 +24,19 @@ class CalendarDayWeekScreen extends StatefulWidget {
|
||||
State<CalendarDayWeekScreen> createState() => _CalendarDayWeekScreenState();
|
||||
}
|
||||
|
||||
class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen>
|
||||
with WidgetsBindingObserver {
|
||||
static const double _dayItemWidth = 44;
|
||||
static const double _dayItemGap = 12;
|
||||
static const double _hourHeight = 34;
|
||||
static const double _eventLeftOffset = 52;
|
||||
static const double _defaultHourHeight = 34.0;
|
||||
static const double _minHourHeight = 17.0;
|
||||
static const double _maxHourHeight = 68.0;
|
||||
|
||||
double _hourHeight = _defaultHourHeight;
|
||||
final Map<int, Offset> _activePointers = {};
|
||||
double? _pinchStartDistance;
|
||||
double _pinchStartHourHeight = _defaultHourHeight;
|
||||
|
||||
late final CalendarStateManager _calendarManager;
|
||||
late DateTime _selectedDate;
|
||||
@@ -36,10 +44,12 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
final ScrollController _dayStripController = ScrollController();
|
||||
Key _eventsKey = UniqueKey();
|
||||
List<ScheduleItemModel> _events = const [];
|
||||
String? _lastRoute;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_calendarManager = sl<CalendarStateManager>();
|
||||
|
||||
if (widget.resetToToday) {
|
||||
@@ -52,9 +62,22 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_scrollToSelectedDate();
|
||||
_lastRoute = GoRouterState.of(context).uri.toString();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final currentRoute = GoRouterState.of(context).uri.toString();
|
||||
if (_lastRoute != null && _lastRoute != currentRoute) {
|
||||
if (!currentRoute.contains('/events/')) {
|
||||
_loadEvents();
|
||||
}
|
||||
}
|
||||
_lastRoute = currentRoute;
|
||||
}
|
||||
|
||||
void _updateMonthDates() {
|
||||
_monthDates = monthDatesFor(_selectedDate);
|
||||
}
|
||||
@@ -71,47 +94,135 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_dayStripController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_loadEvents();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.todoBg,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: AppSpacing.lg,
|
||||
right: AppSpacing.lg,
|
||||
top: 2,
|
||||
bottom: 104,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildWeekStrip(),
|
||||
const SizedBox(height: 8),
|
||||
KeyedSubtree(
|
||||
body: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) {
|
||||
context.go('/calendar/month?date=${formatYmd(_selectedDate)}');
|
||||
}
|
||||
},
|
||||
child: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
top: 154,
|
||||
bottom: 84,
|
||||
child: Listener(
|
||||
onPointerDown: _handlePointerDown,
|
||||
onPointerMove: _handlePointerMove,
|
||||
onPointerUp: _handlePointerUp,
|
||||
onPointerCancel: _handlePointerCancel,
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: AppSpacing.lg,
|
||||
right: AppSpacing.lg,
|
||||
top: 2,
|
||||
),
|
||||
child: KeyedSubtree(
|
||||
key: _eventsKey,
|
||||
child: _buildTimelineBoard(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBottomDock(),
|
||||
],
|
||||
Positioned(top: 0, left: 0, right: 0, child: _buildHeader()),
|
||||
Positioned(top: 68, left: 0, right: 0, child: _buildWeekStrip()),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: _buildBottomDock(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _goToToday() {
|
||||
final today = DateTime.now();
|
||||
setState(() {
|
||||
_selectedDate = today;
|
||||
_hourHeight = _defaultHourHeight;
|
||||
});
|
||||
_calendarManager.setSelectedDate(today);
|
||||
_updateMonthDates();
|
||||
_scrollToSelectedDate(animate: true);
|
||||
_loadEvents();
|
||||
}
|
||||
|
||||
void _handlePointerDown(PointerDownEvent event) {
|
||||
_activePointers[event.pointer] = event.position;
|
||||
if (_activePointers.length == 2) {
|
||||
final pointers = _activePointers.values.toList(growable: false);
|
||||
_pinchStartDistance = (pointers[0] - pointers[1]).distance;
|
||||
_pinchStartHourHeight = _hourHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerMove(PointerMoveEvent event) {
|
||||
if (!_activePointers.containsKey(event.pointer)) {
|
||||
return;
|
||||
}
|
||||
_activePointers[event.pointer] = event.position;
|
||||
if (_activePointers.length != 2 || _pinchStartDistance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final pointers = _activePointers.values.toList(growable: false);
|
||||
final currentDistance = (pointers[0] - pointers[1]).distance;
|
||||
final startDistance = _pinchStartDistance!;
|
||||
if (startDistance <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final nextHeight =
|
||||
(_pinchStartHourHeight * (currentDistance / startDistance)).clamp(
|
||||
_minHourHeight,
|
||||
_maxHourHeight,
|
||||
);
|
||||
if ((nextHeight - _hourHeight).abs() < 0.1) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_hourHeight = nextHeight;
|
||||
});
|
||||
}
|
||||
|
||||
void _handlePointerUp(PointerUpEvent event) {
|
||||
_activePointers.remove(event.pointer);
|
||||
if (_activePointers.length < 2) {
|
||||
_pinchStartDistance = null;
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerCancel(PointerCancelEvent event) {
|
||||
_activePointers.remove(event.pointer);
|
||||
if (_activePointers.length < 2) {
|
||||
_pinchStartDistance = null;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return SizedBox(
|
||||
height: 68,
|
||||
@@ -151,6 +262,31 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (!isSameDay(_selectedDate, DateTime.now()))
|
||||
GestureDetector(
|
||||
onTap: _goToToday,
|
||||
child: Container(
|
||||
height: 36,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.messageBtnWrap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.messageBtnBorder),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'今天',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!isSameDay(_selectedDate, DateTime.now()))
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: () => CreateEventSheet.show(
|
||||
context,
|
||||
@@ -440,7 +576,7 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
bool isDisabled = false,
|
||||
}) {
|
||||
return SizedBox(
|
||||
height: 34,
|
||||
height: _hourHeight,
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/notifications/local_notification_service.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../data/services/mock_calendar_service.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
@@ -161,7 +162,10 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('时间范围', timeStr),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('提醒时间', '开始前30分钟'),
|
||||
_buildDetailField(
|
||||
'提醒时间',
|
||||
_formatReminderText(event.metadata?.reminderMinutes),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildColorField(event.metadata?.color),
|
||||
const SizedBox(height: 14),
|
||||
@@ -176,8 +180,6 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
if (event.metadata?.notes != null) ...[
|
||||
_buildNotesField(event.metadata!.notes!),
|
||||
],
|
||||
const SizedBox(height: 14),
|
||||
_buildMetadataSection(event.metadata),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -186,6 +188,16 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
String _formatReminderText(int? reminderMinutes) {
|
||||
if (reminderMinutes == null) {
|
||||
return '无';
|
||||
}
|
||||
if (reminderMinutes == 0) {
|
||||
return '准时提醒';
|
||||
}
|
||||
return '开始前$reminderMinutes分钟';
|
||||
}
|
||||
|
||||
String _getWeekday(int weekday) {
|
||||
const weekdays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
return weekdays[weekday - 1];
|
||||
@@ -290,6 +302,9 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await sl<CalendarService>().deleteEvent(widget.eventId);
|
||||
await sl<LocalNotificationService>().cancelEventReminder(
|
||||
widget.eventId,
|
||||
);
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
@@ -385,40 +400,6 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMetadataSection(ScheduleMetadata? metadata) {
|
||||
final raw = metadata?.raw ?? const <String, dynamic>{};
|
||||
if (raw.isEmpty) {
|
||||
return _buildDetailField('metadata', '无');
|
||||
}
|
||||
final rows = <String>[];
|
||||
raw.forEach((key, value) {
|
||||
rows.add('$key: $value');
|
||||
});
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'metadata',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
...rows.map(
|
||||
(row) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(
|
||||
row,
|
||||
style: const TextStyle(fontSize: 13, color: AppColors.slate700),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Color _parseColor(String? hex) {
|
||||
if (hex == null || hex.isEmpty) return AppColors.blue600;
|
||||
try {
|
||||
|
||||
@@ -20,16 +20,19 @@ class CalendarMonthScreen extends StatefulWidget {
|
||||
State<CalendarMonthScreen> createState() => _CalendarMonthScreenState();
|
||||
}
|
||||
|
||||
class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
class _CalendarMonthScreenState extends State<CalendarMonthScreen>
|
||||
with WidgetsBindingObserver {
|
||||
late final CalendarStateManager _calendarManager;
|
||||
late DateTime _currentMonth;
|
||||
late DateTime _selectedDate;
|
||||
Key _eventsKey = UniqueKey();
|
||||
final Map<String, List<ScheduleItemModel>> _eventsByDay = {};
|
||||
String? _lastRoute;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_calendarManager = sl<CalendarStateManager>();
|
||||
|
||||
if (widget.resetToToday) {
|
||||
@@ -40,6 +43,22 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
_selectedDate = savedDate;
|
||||
_currentMonth = DateTime(savedDate.year, savedDate.month, 1);
|
||||
_loadMonthEvents();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_lastRoute = GoRouterState.of(context).uri.toString();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final currentRoute = GoRouterState.of(context).uri.toString();
|
||||
if (_lastRoute != null && _lastRoute != currentRoute) {
|
||||
if (!currentRoute.contains('/events/')) {
|
||||
_loadMonthEvents();
|
||||
}
|
||||
}
|
||||
_lastRoute = currentRoute;
|
||||
}
|
||||
|
||||
Future<void> _loadMonthEvents() async {
|
||||
@@ -64,24 +83,45 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_loadMonthEvents();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.todoBg,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 84),
|
||||
child: _buildMonthContent(),
|
||||
body: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) {
|
||||
context.go('/home');
|
||||
}
|
||||
},
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 84),
|
||||
child: _buildMonthContent(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBottomDock(),
|
||||
],
|
||||
_buildBottomDock(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user