2026-02-25 11:10:32 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2026-02-25 12:06:14 +08:00
|
|
|
import 'package:go_router/go_router.dart';
|
2026-02-25 11:10:32 +08:00
|
|
|
import 'package:lucide_icons/lucide_icons.dart';
|
2026-02-27 18:36:21 +08:00
|
|
|
import '../../../../core/di/injection.dart';
|
2026-02-25 11:10:32 +08:00
|
|
|
import '../../../../core/theme/design_tokens.dart';
|
2026-03-16 16:11:28 +08:00
|
|
|
import '../../../../shared/widgets/app_pressable.dart';
|
2026-02-27 18:36:21 +08:00
|
|
|
import '../calendar_state_manager.dart';
|
|
|
|
|
import '../calendar_time_utils.dart';
|
2026-02-25 11:10:32 +08:00
|
|
|
import '../widgets/bottom_dock.dart';
|
2026-03-02 17:28:21 +08:00
|
|
|
import '../widgets/create_event_sheet.dart';
|
2026-03-12 16:41:45 +08:00
|
|
|
import '../../data/services/calendar_service.dart';
|
2026-03-02 17:28:21 +08:00
|
|
|
import '../../data/models/schedule_item_model.dart';
|
2026-02-25 11:10:32 +08:00
|
|
|
|
|
|
|
|
class CalendarDayWeekScreen extends StatefulWidget {
|
2026-02-27 18:36:21 +08:00
|
|
|
final DateTime? initialDate;
|
|
|
|
|
final bool resetToToday;
|
|
|
|
|
|
|
|
|
|
const CalendarDayWeekScreen({
|
|
|
|
|
super.key,
|
|
|
|
|
this.initialDate,
|
|
|
|
|
this.resetToToday = false,
|
|
|
|
|
});
|
2026-02-25 11:10:32 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<CalendarDayWeekScreen> createState() => _CalendarDayWeekScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:16:11 +08:00
|
|
|
class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen>
|
|
|
|
|
with WidgetsBindingObserver {
|
2026-02-27 18:36:21 +08:00
|
|
|
static const double _dayItemWidth = 44;
|
|
|
|
|
static const double _dayItemGap = 12;
|
2026-03-02 17:28:21 +08:00
|
|
|
static const double _eventLeftOffset = 52;
|
2026-03-11 17:16:11 +08:00
|
|
|
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;
|
2026-02-27 18:36:21 +08:00
|
|
|
|
|
|
|
|
late final CalendarStateManager _calendarManager;
|
|
|
|
|
late DateTime _selectedDate;
|
|
|
|
|
late List<DateTime> _monthDates;
|
|
|
|
|
final ScrollController _dayStripController = ScrollController();
|
2026-03-11 15:28:29 +08:00
|
|
|
List<ScheduleItemModel> _events = const [];
|
2026-02-25 11:10:32 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2026-03-11 17:16:11 +08:00
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2026-02-27 18:36:21 +08:00
|
|
|
_calendarManager = sl<CalendarStateManager>();
|
|
|
|
|
|
|
|
|
|
if (widget.resetToToday) {
|
|
|
|
|
_calendarManager.resetToToday();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_selectedDate = _calendarManager.selectedDate;
|
|
|
|
|
_updateMonthDates();
|
2026-03-11 15:28:29 +08:00
|
|
|
_loadEvents();
|
2026-02-27 18:36:21 +08:00
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
_scrollToSelectedDate();
|
2026-03-11 17:32:00 +08:00
|
|
|
_setupRouteListener();
|
2026-02-27 18:36:21 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:32:00 +08:00
|
|
|
void _setupRouteListener() {
|
|
|
|
|
final router = GoRouter.of(context);
|
|
|
|
|
router.routerDelegate.addListener(_onRouteChange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onRouteChange() {
|
|
|
|
|
_loadEvents();
|
2026-03-11 17:16:11 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-27 18:36:21 +08:00
|
|
|
void _updateMonthDates() {
|
|
|
|
|
_monthDates = monthDatesFor(_selectedDate);
|
2026-02-25 11:10:32 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 15:28:29 +08:00
|
|
|
Future<void> _loadEvents() async {
|
|
|
|
|
final events = await sl<CalendarService>().getEventsForDay(_selectedDate);
|
|
|
|
|
if (!mounted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setState(() {
|
|
|
|
|
_events = events;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 18:36:21 +08:00
|
|
|
@override
|
|
|
|
|
void dispose() {
|
2026-03-11 17:32:00 +08:00
|
|
|
try {
|
|
|
|
|
GoRouter.of(context).routerDelegate.removeListener(_onRouteChange);
|
|
|
|
|
} catch (_) {}
|
2026-03-11 17:16:11 +08:00
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
2026-02-27 18:36:21 +08:00
|
|
|
_dayStripController.dispose();
|
|
|
|
|
super.dispose();
|
2026-02-25 11:10:32 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:16:11 +08:00
|
|
|
@override
|
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
|
if (state == AppLifecycleState.resumed) {
|
|
|
|
|
_loadEvents();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:10:32 +08:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
2026-02-27 18:36:21 +08:00
|
|
|
backgroundColor: AppColors.todoBg,
|
2026-03-11 17:16:11 +08:00
|
|
|
body: PopScope(
|
|
|
|
|
canPop: false,
|
|
|
|
|
onPopInvokedWithResult: (didPop, result) {
|
|
|
|
|
if (!didPop) {
|
2026-03-11 20:51:56 +08:00
|
|
|
context.go('/home');
|
2026-03-11 17:16:11 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
|
),
|
2026-03-16 16:11:28 +08:00
|
|
|
child: RepaintBoundary(child: _buildTimelineBoard()),
|
2026-03-11 17:16:11 +08:00
|
|
|
),
|
2026-02-25 11:10:32 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-03-11 17:16:11 +08:00
|
|
|
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(),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-02-25 11:10:32 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:16:11 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:10:32 +08:00
|
|
|
Widget _buildHeader() {
|
2026-03-16 16:11:28 +08:00
|
|
|
final monthLabel = '${_selectedDate.year}年${_selectedDate.month}月';
|
|
|
|
|
|
2026-02-25 11:10:32 +08:00
|
|
|
return SizedBox(
|
|
|
|
|
height: 68,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 20, right: 20, top: 12, bottom: 8),
|
|
|
|
|
child: Row(
|
2026-03-16 16:11:28 +08:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2026-02-25 11:10:32 +08:00
|
|
|
children: [
|
2026-03-16 16:11:28 +08:00
|
|
|
AppPressable(
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.xl),
|
2026-02-27 18:36:21 +08:00
|
|
|
onTap: () => context.go('/calendar/month'),
|
2026-02-25 11:10:32 +08:00
|
|
|
child: Container(
|
|
|
|
|
height: 36,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
|
|
|
|
decoration: BoxDecoration(
|
2026-02-27 18:36:21 +08:00
|
|
|
color: AppColors.messageBtnWrap,
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.xl),
|
|
|
|
|
border: Border.all(color: AppColors.messageBtnBorder),
|
2026-02-25 11:10:32 +08:00
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
2026-03-16 16:11:28 +08:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2026-02-25 11:10:32 +08:00
|
|
|
children: [
|
|
|
|
|
const Icon(
|
|
|
|
|
LucideIcons.chevronLeft,
|
|
|
|
|
size: 16,
|
|
|
|
|
color: AppColors.slate700,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 6),
|
2026-03-16 16:11:28 +08:00
|
|
|
AnimatedSwitcher(
|
|
|
|
|
duration: const Duration(milliseconds: 160),
|
|
|
|
|
switchInCurve: Curves.easeOut,
|
|
|
|
|
switchOutCurve: Curves.easeOut,
|
|
|
|
|
transitionBuilder: (child, animation) {
|
|
|
|
|
return FadeTransition(
|
|
|
|
|
opacity: animation,
|
|
|
|
|
child: SlideTransition(
|
|
|
|
|
position: Tween<Offset>(
|
|
|
|
|
begin: const Offset(0, 0.12),
|
|
|
|
|
end: Offset.zero,
|
|
|
|
|
).animate(animation),
|
|
|
|
|
child: child,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Text(
|
|
|
|
|
monthLabel,
|
|
|
|
|
key: ValueKey(monthLabel),
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: AppColors.slate700,
|
|
|
|
|
),
|
2026-02-25 11:10:32 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-03-02 17:28:21 +08:00
|
|
|
const Spacer(),
|
2026-03-11 17:16:11 +08:00
|
|
|
if (!isSameDay(_selectedDate, DateTime.now()))
|
2026-03-16 16:11:28 +08:00
|
|
|
AppPressable(
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.xl),
|
2026-03-11 17:16:11 +08:00
|
|
|
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),
|
2026-03-16 16:11:28 +08:00
|
|
|
AppPressable(
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.full),
|
2026-03-02 17:28:21 +08:00
|
|
|
onTap: () => CreateEventSheet.show(
|
|
|
|
|
context,
|
|
|
|
|
initialDate: _selectedDate,
|
2026-03-16 16:11:28 +08:00
|
|
|
onSaved: _loadEvents,
|
2026-03-02 17:28:21 +08:00
|
|
|
),
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 36,
|
|
|
|
|
height: 36,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.blue600,
|
2026-03-16 16:11:28 +08:00
|
|
|
borderRadius: BorderRadius.circular(AppRadius.full),
|
2026-03-02 17:28:21 +08:00
|
|
|
),
|
|
|
|
|
child: const Icon(
|
|
|
|
|
LucideIcons.plus,
|
|
|
|
|
size: 20,
|
2026-03-16 16:11:28 +08:00
|
|
|
color: AppColors.white,
|
2026-03-02 17:28:21 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-02-25 11:10:32 +08:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildWeekStrip() {
|
2026-03-16 16:11:28 +08:00
|
|
|
final stripKey = ValueKey('${_selectedDate.year}-${_selectedDate.month}');
|
|
|
|
|
|
2026-02-25 11:10:32 +08:00
|
|
|
return SizedBox(
|
|
|
|
|
height: 86,
|
2026-03-16 16:11:28 +08:00
|
|
|
child: AnimatedSwitcher(
|
|
|
|
|
duration: const Duration(milliseconds: 180),
|
|
|
|
|
switchInCurve: Curves.easeOut,
|
|
|
|
|
switchOutCurve: Curves.easeOut,
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
key: stripKey,
|
|
|
|
|
controller: _dayStripController,
|
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
|
itemCount: _monthDates.length,
|
|
|
|
|
separatorBuilder: (context, index) =>
|
|
|
|
|
const SizedBox(width: _dayItemGap),
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final date = _monthDates[index];
|
|
|
|
|
final isSelected = isSameDay(date, _selectedDate);
|
|
|
|
|
final isWeekend = date.weekday % 7 == 0 || date.weekday % 7 == 6;
|
|
|
|
|
|
|
|
|
|
return AppPressable(
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.xl),
|
|
|
|
|
onTap: () {
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedDate = date;
|
|
|
|
|
});
|
|
|
|
|
_calendarManager.setSelectedDate(date);
|
|
|
|
|
_updateMonthDates();
|
|
|
|
|
_scrollToSelectedDate(animate: true);
|
|
|
|
|
_loadEvents();
|
|
|
|
|
},
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
width: _dayItemWidth,
|
|
|
|
|
child: _buildDayItem(date, isSelected, isWeekend),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2026-02-25 11:10:32 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 18:36:21 +08:00
|
|
|
void _scrollToSelectedDate({bool animate = false}) {
|
|
|
|
|
if (!_dayStripController.hasClients) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final index = _monthDates.indexWhere(
|
|
|
|
|
(date) => isSameDay(date, _selectedDate),
|
|
|
|
|
);
|
|
|
|
|
if (index < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final targetCenter =
|
|
|
|
|
index * (_dayItemWidth + _dayItemGap) + (_dayItemWidth / 2);
|
|
|
|
|
final viewport = _dayStripController.position.viewportDimension;
|
|
|
|
|
var offset = targetCenter - (viewport / 2);
|
|
|
|
|
final max = _dayStripController.position.maxScrollExtent;
|
|
|
|
|
if (offset < 0) {
|
|
|
|
|
offset = 0;
|
|
|
|
|
}
|
|
|
|
|
if (offset > max) {
|
|
|
|
|
offset = max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (animate) {
|
|
|
|
|
_dayStripController.animateTo(
|
|
|
|
|
offset,
|
|
|
|
|
duration: const Duration(milliseconds: 180),
|
|
|
|
|
curve: Curves.easeOut,
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_dayStripController.jumpTo(offset);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:10:32 +08:00
|
|
|
Widget _buildDayItem(DateTime date, bool isSelected, bool isWeekend) {
|
|
|
|
|
final dayNames = ['日', '一', '二', '三', '四', '五', '六'];
|
|
|
|
|
|
|
|
|
|
return Column(
|
2026-03-16 16:11:28 +08:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2026-02-25 11:10:32 +08:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
dayNames[date.weekday % 7],
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
color: isWeekend ? AppColors.slate400 : AppColors.slate600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 2),
|
2026-03-16 16:11:28 +08:00
|
|
|
AnimatedContainer(
|
|
|
|
|
duration: const Duration(milliseconds: 140),
|
|
|
|
|
curve: Curves.easeOut,
|
|
|
|
|
width: 32,
|
|
|
|
|
height: 32,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: isSelected ? AppColors.blue100 : Colors.transparent,
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.full),
|
|
|
|
|
),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
'${date.day}',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 17,
|
|
|
|
|
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w600,
|
|
|
|
|
color: isSelected
|
|
|
|
|
? AppColors.blue600
|
|
|
|
|
: (isWeekend ? AppColors.slate400 : AppColors.slate900),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-02-25 11:10:32 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildTimelineBoard() {
|
2026-02-27 18:36:21 +08:00
|
|
|
final now = DateTime.now();
|
|
|
|
|
final showCurrent = shouldShowCurrentMarker(_selectedDate, now);
|
2026-03-11 15:28:29 +08:00
|
|
|
final events = _events;
|
2026-03-02 17:28:21 +08:00
|
|
|
|
|
|
|
|
final eventColumns = _calculateEventColumns(events);
|
|
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
|
child: Stack(
|
|
|
|
|
clipBehavior: Clip.none,
|
|
|
|
|
children: [
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
for (var hour = 0; hour <= 23; hour++) ...[
|
|
|
|
|
_buildTimelineRow(formatHour(hour)),
|
|
|
|
|
if (showCurrent && now.hour == hour)
|
|
|
|
|
_buildTimelineRow(formatHm(now), isCurrentTime: true),
|
|
|
|
|
],
|
|
|
|
|
_buildTimelineRow(formatHour(24), isDisabled: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
..._buildPositionedEvents(events, eventColumns),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<int> _calculateEventColumns(List<ScheduleItemModel> events) {
|
|
|
|
|
if (events.isEmpty) return [];
|
|
|
|
|
|
|
|
|
|
final columns = List<int>.filled(events.length, -1);
|
|
|
|
|
final columnHeights = <int, int>{};
|
2026-02-27 18:36:21 +08:00
|
|
|
|
2026-03-02 17:28:21 +08:00
|
|
|
for (var i = 0; i < events.length; i++) {
|
|
|
|
|
final event = events[i];
|
|
|
|
|
final eventStart = event.startAt.hour * 60 + event.startAt.minute;
|
|
|
|
|
final eventEnd = event.endAt != null
|
|
|
|
|
? event.endAt!.hour * 60 + event.endAt!.minute
|
|
|
|
|
: eventStart + 60;
|
|
|
|
|
|
|
|
|
|
var column = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
final columnEnd = columnHeights[column] ?? 0;
|
|
|
|
|
if (columnEnd <= eventStart) {
|
|
|
|
|
columns[i] = column;
|
|
|
|
|
columnHeights[column] = eventEnd;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
column++;
|
2026-02-27 18:36:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 17:28:21 +08:00
|
|
|
return columns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Widget> _buildPositionedEvents(
|
|
|
|
|
List<ScheduleItemModel> events,
|
|
|
|
|
List<int> columns,
|
|
|
|
|
) {
|
|
|
|
|
if (events.isEmpty) return [];
|
|
|
|
|
|
|
|
|
|
final maxColumn = columns.reduce((a, b) => a > b ? a : b) + 1;
|
|
|
|
|
final eventWidgets = <Widget>[];
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < events.length; i++) {
|
|
|
|
|
final event = events[i];
|
|
|
|
|
final column = columns[i];
|
2026-03-16 16:11:28 +08:00
|
|
|
final eventColor = _parseColor(event.metadata?.color);
|
2026-03-02 17:28:21 +08:00
|
|
|
|
|
|
|
|
final startMinutes = event.startAt.hour * 60 + event.startAt.minute;
|
|
|
|
|
final endMinutes = event.endAt != null
|
|
|
|
|
? event.endAt!.hour * 60 + event.endAt!.minute
|
|
|
|
|
: startMinutes + 60;
|
|
|
|
|
final durationMinutes = endMinutes - startMinutes;
|
|
|
|
|
|
|
|
|
|
final top = (startMinutes / 60) * _hourHeight;
|
|
|
|
|
final height = (durationMinutes / 60) * _hourHeight;
|
|
|
|
|
|
|
|
|
|
final eventWidth = maxColumn > 1
|
|
|
|
|
? (MediaQuery.of(context).size.width - _eventLeftOffset - 16) /
|
|
|
|
|
maxColumn
|
|
|
|
|
: MediaQuery.of(context).size.width - _eventLeftOffset - 16;
|
|
|
|
|
final left = _eventLeftOffset + column * eventWidth;
|
|
|
|
|
|
|
|
|
|
eventWidgets.add(
|
|
|
|
|
Positioned(
|
|
|
|
|
top: top,
|
|
|
|
|
left: left,
|
|
|
|
|
right: maxColumn > 1 ? null : 16,
|
|
|
|
|
width: maxColumn > 1 ? eventWidth - 4 : null,
|
|
|
|
|
height: height.clamp(24.0, double.infinity),
|
|
|
|
|
child: Material(
|
|
|
|
|
color: Colors.transparent,
|
|
|
|
|
child: InkWell(
|
|
|
|
|
onTap: () {
|
2026-03-16 16:11:28 +08:00
|
|
|
context.push('/calendar/events/${event.id}');
|
2026-03-02 17:28:21 +08:00
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
margin: const EdgeInsets.only(right: 4),
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
|
|
|
|
decoration: BoxDecoration(
|
2026-03-16 16:11:28 +08:00
|
|
|
color: eventColor.withValues(alpha: 0.2),
|
2026-03-02 17:28:21 +08:00
|
|
|
borderRadius: BorderRadius.circular(4),
|
2026-03-16 16:11:28 +08:00
|
|
|
border: Border.all(color: eventColor, width: 1),
|
2026-03-02 17:28:21 +08:00
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
width: 6,
|
|
|
|
|
height: 6,
|
|
|
|
|
decoration: BoxDecoration(
|
2026-03-16 16:11:28 +08:00
|
|
|
color: eventColor,
|
2026-03-02 17:28:21 +08:00
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
event.title,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
2026-03-16 16:11:28 +08:00
|
|
|
color: eventColor,
|
2026-03-02 17:28:21 +08:00
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return eventWidgets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color _parseColor(String? hex) {
|
|
|
|
|
if (hex == null || hex.isEmpty) return AppColors.blue600;
|
|
|
|
|
try {
|
|
|
|
|
return Color(int.parse(hex.replaceFirst('#', '0xFF')));
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return AppColors.blue600;
|
|
|
|
|
}
|
2026-02-25 11:10:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildTimelineRow(
|
2026-02-27 18:36:21 +08:00
|
|
|
String time, {
|
2026-02-25 11:10:32 +08:00
|
|
|
bool isCurrentTime = false,
|
|
|
|
|
bool isDisabled = false,
|
|
|
|
|
}) {
|
|
|
|
|
return SizedBox(
|
2026-03-11 17:16:11 +08:00
|
|
|
height: _hourHeight,
|
2026-02-25 11:10:32 +08:00
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 44,
|
|
|
|
|
child: isCurrentTime
|
|
|
|
|
? Container(
|
|
|
|
|
width: 44,
|
|
|
|
|
height: 18,
|
|
|
|
|
decoration: BoxDecoration(
|
2026-02-27 18:36:21 +08:00
|
|
|
color: AppColors.red500,
|
2026-02-25 11:10:32 +08:00
|
|
|
borderRadius: BorderRadius.circular(9),
|
|
|
|
|
),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
time,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
fontWeight: FontWeight.w700,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Text(
|
|
|
|
|
time,
|
|
|
|
|
textAlign: TextAlign.right,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: isDisabled
|
|
|
|
|
? AppColors.slate300
|
2026-02-27 18:36:21 +08:00
|
|
|
: AppColors.slate400,
|
2026-02-25 11:10:32 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: isCurrentTime
|
|
|
|
|
? Container(
|
|
|
|
|
height: 2,
|
|
|
|
|
decoration: BoxDecoration(
|
2026-02-27 18:36:21 +08:00
|
|
|
color: AppColors.red500,
|
2026-02-25 11:10:32 +08:00
|
|
|
borderRadius: BorderRadius.circular(99),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Container(
|
|
|
|
|
height: 1,
|
2026-02-27 18:36:21 +08:00
|
|
|
color: isDisabled ? AppColors.blue50 : AppColors.border,
|
2026-02-25 11:10:32 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildBottomDock() {
|
|
|
|
|
return BottomDock(
|
|
|
|
|
activeTab: DockTab.calendar,
|
2026-02-27 18:36:21 +08:00
|
|
|
onTodoTap: () {
|
|
|
|
|
_calendarManager.setViewType(CalendarViewType.day);
|
|
|
|
|
context.push('/todo');
|
|
|
|
|
},
|
|
|
|
|
onCalendarTap: () {
|
|
|
|
|
_calendarManager.setViewType(CalendarViewType.day);
|
|
|
|
|
context.go('/calendar/month');
|
|
|
|
|
},
|
|
|
|
|
onHomeTap: () => context.go('/home'),
|
2026-02-25 11:10:32 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|