feat: 增强日历功能并集成 AgentScope 代理服务

This commit is contained in:
qzl
2026-03-11 17:16:11 +08:00
parent e20e7d2a02
commit 85b314cf64
53 changed files with 3642 additions and 297 deletions
@@ -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(