fix: 修复日历事件详情页布局问题并添加底部输入框
- 修复 Row 中 Flexible 在无界宽度约束下的布局崩溃问题 - 用 Expanded 包裹内层 Row 提供有界宽度约束 - 添加底部输入框组件(+按钮、输入框、麦克风图标) - 实现事件详情页动态数据展示 - 添加编辑和删除事件功能 - 添加事件不存在时的错误页面
This commit is contained in:
@@ -6,6 +6,9 @@ import '../../../../core/theme/design_tokens.dart';
|
||||
import '../calendar_state_manager.dart';
|
||||
import '../calendar_time_utils.dart';
|
||||
import '../widgets/bottom_dock.dart';
|
||||
import '../widgets/create_event_sheet.dart';
|
||||
import '../../data/services/mock_calendar_service.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
|
||||
class CalendarDayWeekScreen extends StatefulWidget {
|
||||
final DateTime? initialDate;
|
||||
@@ -24,11 +27,14 @@ class CalendarDayWeekScreen extends StatefulWidget {
|
||||
class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
static const double _dayItemWidth = 44;
|
||||
static const double _dayItemGap = 12;
|
||||
static const double _hourHeight = 34;
|
||||
static const double _eventLeftOffset = 52;
|
||||
|
||||
late final CalendarStateManager _calendarManager;
|
||||
late DateTime _selectedDate;
|
||||
late List<DateTime> _monthDates;
|
||||
final ScrollController _dayStripController = ScrollController();
|
||||
Key _eventsKey = UniqueKey();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -78,7 +84,10 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
children: [
|
||||
_buildWeekStrip(),
|
||||
const SizedBox(height: 8),
|
||||
_buildTimelineBoard(),
|
||||
KeyedSubtree(
|
||||
key: _eventsKey,
|
||||
child: _buildTimelineBoard(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -129,6 +138,31 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () => CreateEventSheet.show(
|
||||
context,
|
||||
initialDate: _selectedDate,
|
||||
onSaved: () {
|
||||
setState(() {
|
||||
_eventsKey = UniqueKey();
|
||||
});
|
||||
},
|
||||
),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue600,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.plus,
|
||||
size: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -233,17 +267,157 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen> {
|
||||
Widget _buildTimelineBoard() {
|
||||
final now = DateTime.now();
|
||||
final showCurrent = shouldShowCurrentMarker(_selectedDate, now);
|
||||
final rows = <Widget>[];
|
||||
final events = CalendarService().getEventsForDay(_selectedDate);
|
||||
|
||||
for (var hour = 7; hour <= 22; hour++) {
|
||||
rows.add(_buildTimelineRow(formatHour(hour)));
|
||||
if (showCurrent && now.hour == hour) {
|
||||
rows.add(_buildTimelineRow(formatHm(now), isCurrentTime: true));
|
||||
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>{};
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
rows.add(_buildTimelineRow(formatHour(24), isDisabled: true));
|
||||
return Column(children: rows);
|
||||
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];
|
||||
|
||||
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: () {
|
||||
final path = '/calendar/events/${event.id}';
|
||||
debugPrint('Navigating to: $path');
|
||||
context.push(path);
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(right: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: _parseColor(
|
||||
event.metadata?.color,
|
||||
).withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(
|
||||
color: _parseColor(event.metadata?.color),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: _parseColor(event.metadata?.color),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
event.title,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: _parseColor(event.metadata?.color),
|
||||
),
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildTimelineRow(
|
||||
|
||||
@@ -1,19 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../data/services/mock_calendar_service.dart';
|
||||
import '../../data/models/schedule_item_model.dart';
|
||||
import '../widgets/create_event_sheet.dart';
|
||||
|
||||
class CalendarEventDetailScreen extends StatelessWidget {
|
||||
const CalendarEventDetailScreen({super.key});
|
||||
class CalendarEventDetailScreen extends StatefulWidget {
|
||||
final String eventId;
|
||||
|
||||
const CalendarEventDetailScreen({super.key, required this.eventId});
|
||||
|
||||
@override
|
||||
State<CalendarEventDetailScreen> createState() =>
|
||||
_CalendarEventDetailScreenState();
|
||||
}
|
||||
|
||||
class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
ScheduleItemModel? _event;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadEvent();
|
||||
}
|
||||
|
||||
void _loadEvent() {
|
||||
try {
|
||||
_event = CalendarService().getEventById(widget.eventId);
|
||||
} catch (e) {
|
||||
_event = null;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_event == null) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8FAFC),
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'Event not found',
|
||||
style: TextStyle(color: AppColors.slate600),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
GestureDetector(
|
||||
onTap: () => context.pop(),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue600,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: const Text(
|
||||
'返回',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final event = _event!;
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8FAFC),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(context),
|
||||
Expanded(child: _buildDetailOverlay()),
|
||||
Expanded(child: _buildDetailOverlay(event)),
|
||||
_buildInputContainer(),
|
||||
],
|
||||
),
|
||||
@@ -51,7 +118,15 @@ class CalendarEventDetailScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailOverlay() {
|
||||
Widget _buildDetailOverlay(ScheduleItemModel event) {
|
||||
final startAt = event.startAt;
|
||||
final endAt = event.endAt;
|
||||
final dateStr =
|
||||
'${startAt.year}年${startAt.month}月${startAt.day}日 ${_getWeekday(startAt.weekday)}';
|
||||
final timeStr = endAt != null
|
||||
? '${_formatTime(startAt)} - ${_formatTime(endAt)}'
|
||||
: _formatTime(startAt);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 12),
|
||||
child: Container(
|
||||
@@ -62,82 +137,124 @@ class CalendarEventDetailScreen extends StatelessWidget {
|
||||
border: Border.all(color: const Color(0xFFD8E3F5)),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildTitleRow(),
|
||||
const SizedBox(height: 14),
|
||||
Container(height: 1, color: const Color(0xFFE5E7EB)),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('日期', '2026年2月9日 周一'),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('时间范围', '16:00 - 17:30'),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('提醒时间', '开始前30分钟'),
|
||||
const SizedBox(height: 14),
|
||||
_buildColorField(),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('邀请人', 'Qiuzh'),
|
||||
const SizedBox(height: 14),
|
||||
_buildNotesField(),
|
||||
],
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildTitleRow(event),
|
||||
const SizedBox(height: 14),
|
||||
Container(height: 1, color: const Color(0xFFE5E7EB)),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('日期', dateStr),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('时间范围', timeStr),
|
||||
const SizedBox(height: 14),
|
||||
_buildDetailField('提醒时间', '开始前30分钟'),
|
||||
const SizedBox(height: 14),
|
||||
_buildColorField(event.metadata?.color),
|
||||
const SizedBox(height: 14),
|
||||
if (event.metadata?.location != null) ...[
|
||||
_buildDetailField('地点', event.metadata!.location!),
|
||||
const SizedBox(height: 14),
|
||||
],
|
||||
if (event.description != null) ...[
|
||||
_buildDetailField('描述', event.description!),
|
||||
const SizedBox(height: 14),
|
||||
],
|
||||
if (event.metadata?.notes != null) ...[
|
||||
_buildNotesField(event.metadata!.notes!),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTitleRow() {
|
||||
String _getWeekday(int weekday) {
|
||||
const weekdays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
return weekdays[weekday - 1];
|
||||
}
|
||||
|
||||
String _formatTime(DateTime time) {
|
||||
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
Widget _buildTitleRow(ScheduleItemModel event) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
LucideIcons.calendarCheck2,
|
||||
size: 18,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Text(
|
||||
'购票提醒',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: _parseColor(event.metadata?.color),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: Text(
|
||||
event.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8FAFF),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFDCE5F4)),
|
||||
GestureDetector(
|
||||
onTap: () => CreateEventSheet.edit(
|
||||
context,
|
||||
event,
|
||||
onSaved: () {
|
||||
setState(() {
|
||||
_loadEvent();
|
||||
});
|
||||
},
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.pencil,
|
||||
size: 18,
|
||||
color: AppColors.slate600,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8FAFF),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFDCE5F4)),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.pencil,
|
||||
size: 18,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF1F2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFFECACA)),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.trash2,
|
||||
size: 18,
|
||||
color: AppColors.red500,
|
||||
GestureDetector(
|
||||
onTap: _showDeleteConfirmation,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF1F2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFFECACA)),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.trash2,
|
||||
size: 18,
|
||||
color: AppColors.red500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -146,6 +263,30 @@ class CalendarEventDetailScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteConfirmation() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('删除日程'),
|
||||
content: const Text('确定要删除这个日程吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
CalendarService().deleteEvent(widget.eventId);
|
||||
Navigator.pop(context);
|
||||
context.pop();
|
||||
},
|
||||
child: Text('删除', style: TextStyle(color: AppColors.red500)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailField(String label, String value) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -171,7 +312,8 @@ class CalendarEventDetailScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildColorField() {
|
||||
Widget _buildColorField(String? colorHex) {
|
||||
final color = _parseColor(colorHex);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -186,39 +328,18 @@ class CalendarEventDetailScreen extends StatelessWidget {
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
_buildColorOption(const Color(0xFF3B82F6), isSelected: true),
|
||||
const SizedBox(width: 10),
|
||||
_buildColorOption(const Color(0xFF8B5CF6)),
|
||||
const SizedBox(width: 10),
|
||||
_buildColorOption(const Color(0xFF10B981)),
|
||||
const SizedBox(width: 10),
|
||||
_buildColorOption(const Color(0xFFF59E0B)),
|
||||
const SizedBox(width: 10),
|
||||
_buildColorOption(const Color(0xFFEF4444)),
|
||||
Container(
|
||||
width: 28,
|
||||
height: 28,
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildColorOption(Color color, {bool isSelected = false}) {
|
||||
return Container(
|
||||
width: 28,
|
||||
height: 28,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
border: isSelected
|
||||
? Border.all(color: AppColors.slate900, width: 2)
|
||||
: null,
|
||||
),
|
||||
child: isSelected
|
||||
? const Icon(Icons.check, size: 16, color: Colors.white)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotesField() {
|
||||
Widget _buildNotesField(String notes) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -239,25 +360,24 @@ class CalendarEventDetailScreen extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFDCE5F4)),
|
||||
),
|
||||
child: const Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'记得提前准备好身份证',
|
||||
style: TextStyle(fontSize: 14, color: AppColors.slate700),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'出发前检查车票信息',
|
||||
style: TextStyle(fontSize: 14, color: AppColors.slate700),
|
||||
),
|
||||
],
|
||||
child: Text(
|
||||
notes,
|
||||
style: const TextStyle(fontSize: 14, color: AppColors.slate700),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -271,7 +391,7 @@ class CalendarEventDetailScreen extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
border: Border.all(color: const Color(0xFFE2E8F0)),
|
||||
border: Border.all(color: const Color(0xFFDCE5F4)),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.plus,
|
||||
|
||||
@@ -7,6 +7,8 @@ import '../../../../core/theme/design_tokens.dart';
|
||||
import '../calendar_state_manager.dart';
|
||||
import '../calendar_time_utils.dart';
|
||||
import '../widgets/bottom_dock.dart';
|
||||
import '../widgets/create_event_sheet.dart';
|
||||
import '../../data/services/mock_calendar_service.dart';
|
||||
|
||||
class CalendarMonthScreen extends StatefulWidget {
|
||||
final bool resetToToday;
|
||||
@@ -21,6 +23,7 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
late final CalendarStateManager _calendarManager;
|
||||
late DateTime _currentMonth;
|
||||
late DateTime _selectedDate;
|
||||
Key _eventsKey = UniqueKey();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -91,6 +94,30 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: () => CreateEventSheet.show(
|
||||
context,
|
||||
onSaved: () {
|
||||
setState(() {
|
||||
_eventsKey = UniqueKey();
|
||||
});
|
||||
},
|
||||
),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue600,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.plus,
|
||||
size: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -223,13 +250,25 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildWeekEvents(weekStart, startWeekday, daysInMonth),
|
||||
KeyedSubtree(
|
||||
key: _eventsKey,
|
||||
child: _buildWeekEvents(weekStart, startWeekday, daysInMonth),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWeekEvents(int weekStart, int startWeekday, int daysInMonth) {
|
||||
final firstDayOfMonth = DateTime(
|
||||
_currentMonth.year,
|
||||
_currentMonth.month,
|
||||
1,
|
||||
);
|
||||
final weekFirstDate = firstDayOfMonth.add(
|
||||
Duration(days: weekStart - startWeekday),
|
||||
);
|
||||
|
||||
return SizedBox(
|
||||
height: 70,
|
||||
child: Row(
|
||||
@@ -239,12 +278,81 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen> {
|
||||
if (dayIndex < 1 || dayIndex > daysInMonth) {
|
||||
return const SizedBox(width: 38, height: 1);
|
||||
}
|
||||
return const SizedBox(width: 38, height: 20);
|
||||
|
||||
final date = weekFirstDate.add(Duration(days: index));
|
||||
final events = CalendarService().getEventsForDay(date);
|
||||
final displayEvents = events.take(2).toList();
|
||||
final remainingCount = events.length - 2;
|
||||
|
||||
return SizedBox(
|
||||
width: 38,
|
||||
height: 70,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...displayEvents.map((event) {
|
||||
final color = _parseColor(event.metadata?.color);
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_calendarManager.setSelectedDate(date);
|
||||
context.push('/calendar/events/${event.id}');
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 2),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 4,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
event.title,
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
color: color,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
if (remainingCount > 0)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_calendarManager.setSelectedDate(date);
|
||||
_calendarManager.setViewType(CalendarViewType.day);
|
||||
context.push('/calendar/dayweek?date=${formatYmd(date)}');
|
||||
},
|
||||
child: Text(
|
||||
'+$remainingCount',
|
||||
style: const TextStyle(
|
||||
fontSize: 9,
|
||||
color: AppColors.slate500,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
|
||||
Reference in New Issue
Block a user