fix: 修复日历事件详情页布局问题并添加底部输入框
- 修复 Row 中 Flexible 在无界宽度约束下的布局崩溃问题 - 用 Expanded 包裹内层 Row 提供有界宽度约束 - 添加底部输入框组件(+按钮、输入框、麦克风图标) - 实现事件详情页动态数据展示 - 添加编辑和删除事件功能 - 添加事件不存在时的错误页面
This commit is contained in:
@@ -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