refactor: 重构 Agent 模块为 AgentScope,删除旧版 CrewAI/LiteLLM 实现
This commit is contained in:
@@ -6,6 +6,9 @@ abstract class ApiException implements Exception {
|
||||
|
||||
const ApiException(this.message, {this.statusCode});
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
|
||||
factory ApiException.fromDioError(Object error) {
|
||||
if (error is ApiException) return error;
|
||||
if (error is DioException) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import '../../features/calendar/ui/calendar_state_manager.dart';
|
||||
import '../../features/friends/data/friends_api.dart';
|
||||
import '../../features/messages/data/inbox_api.dart';
|
||||
import '../../features/users/data/users_api.dart';
|
||||
import '../../features/todo/data/todo_api.dart';
|
||||
|
||||
final sl = GetIt.instance;
|
||||
|
||||
@@ -65,6 +66,9 @@ Future<void> configureDependencies() async {
|
||||
final inboxApi = InboxApi(apiClient);
|
||||
sl.registerSingleton<InboxApi>(inboxApi);
|
||||
|
||||
final todoApi = TodoApi(apiClient);
|
||||
sl.registerSingleton<TodoApi>(todoApi);
|
||||
|
||||
final authRepository = AuthRepositoryImpl(
|
||||
api: authApi,
|
||||
tokenStorage: tokenStorage,
|
||||
|
||||
@@ -124,7 +124,8 @@ GoRouter createAppRouter(AuthBloc authBloc) {
|
||||
),
|
||||
GoRoute(
|
||||
path: '/todo/:id',
|
||||
builder: (context, state) => const TodoDetailScreen(),
|
||||
builder: (context, state) =>
|
||||
TodoDetailScreen(todoId: state.pathParameters['id']!),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/settings',
|
||||
|
||||
@@ -46,4 +46,30 @@ class CalendarApi {
|
||||
Future<void> delete(String id) async {
|
||||
await _client.delete('$_prefix/$id');
|
||||
}
|
||||
|
||||
Future<void> acceptSubscription(String itemId) async {
|
||||
await _client.post('$_prefix/$itemId/accept');
|
||||
}
|
||||
|
||||
Future<void> rejectSubscription(String itemId) async {
|
||||
await _client.post('$_prefix/$itemId/reject');
|
||||
}
|
||||
|
||||
Future<void> share(
|
||||
String itemId, {
|
||||
required String email,
|
||||
bool view = true,
|
||||
bool edit = false,
|
||||
bool invite = false,
|
||||
}) async {
|
||||
await _client.post(
|
||||
'$_prefix/$itemId/share',
|
||||
data: {
|
||||
'email': email,
|
||||
'permission_view': view,
|
||||
'permission_edit': edit,
|
||||
'permission_invite': invite,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ enum ScheduleStatus { active, completed, canceled, archived }
|
||||
|
||||
class ScheduleItemModel {
|
||||
final String id;
|
||||
final String ownerId;
|
||||
final int permission;
|
||||
final bool isOwner;
|
||||
final String title;
|
||||
final String? description;
|
||||
final DateTime startAt;
|
||||
@@ -17,8 +20,19 @@ class ScheduleItemModel {
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
|
||||
static const int PERMISSION_VIEW = 1;
|
||||
static const int PERMISSION_INVITE = 2;
|
||||
static const int PERMISSION_EDIT = 4;
|
||||
|
||||
bool get canEdit => isOwner || (permission & PERMISSION_EDIT) != 0;
|
||||
bool get canInvite => isOwner || (permission & PERMISSION_INVITE) != 0;
|
||||
bool get canDelete => isOwner;
|
||||
|
||||
ScheduleItemModel({
|
||||
required this.id,
|
||||
required this.ownerId,
|
||||
this.permission = 1,
|
||||
this.isOwner = false,
|
||||
required this.title,
|
||||
this.description,
|
||||
required this.startAt,
|
||||
@@ -34,6 +48,9 @@ class ScheduleItemModel {
|
||||
|
||||
ScheduleItemModel copyWith({
|
||||
String? id,
|
||||
String? ownerId,
|
||||
int? permission,
|
||||
bool? isOwner,
|
||||
String? title,
|
||||
String? description,
|
||||
DateTime? startAt,
|
||||
@@ -47,6 +64,9 @@ class ScheduleItemModel {
|
||||
}) {
|
||||
return ScheduleItemModel(
|
||||
id: id ?? this.id,
|
||||
ownerId: ownerId ?? this.ownerId,
|
||||
permission: permission ?? this.permission,
|
||||
isOwner: isOwner ?? this.isOwner,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
startAt: startAt ?? this.startAt,
|
||||
@@ -63,6 +83,9 @@ class ScheduleItemModel {
|
||||
factory ScheduleItemModel.fromJson(Map<String, dynamic> json) {
|
||||
return ScheduleItemModel(
|
||||
id: json['id'] as String,
|
||||
ownerId: json['owner_id'] as String? ?? '',
|
||||
permission: json['permission'] as int? ?? 1,
|
||||
isOwner: json['is_owner'] as bool? ?? false,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String?,
|
||||
startAt: DateTime.parse(json['start_at'] as String).toLocal(),
|
||||
|
||||
@@ -113,7 +113,7 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen>
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) {
|
||||
context.go('/calendar/month?date=${formatYmd(_selectedDate)}');
|
||||
context.go('/home');
|
||||
}
|
||||
},
|
||||
child: SafeArea(
|
||||
|
||||
@@ -7,6 +7,7 @@ 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';
|
||||
import '../widgets/calendar_share_dialog.dart';
|
||||
|
||||
class CalendarEventDetailScreen extends StatefulWidget {
|
||||
final String eventId;
|
||||
@@ -239,49 +240,77 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => CreateEventSheet.edit(
|
||||
context,
|
||||
event,
|
||||
onSaved: () {
|
||||
setState(() {
|
||||
_loadEvent();
|
||||
});
|
||||
},
|
||||
),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8FAFF),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFDCE5F4)),
|
||||
if (event.canEdit)
|
||||
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),
|
||||
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,
|
||||
if (event.canEdit) const SizedBox(width: 8),
|
||||
if (event.canDelete)
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (event.canInvite) ...[
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: () => CalendarShareDialog.show(
|
||||
context,
|
||||
event.id,
|
||||
event.title,
|
||||
canInvite: event.canInvite,
|
||||
canEdit: event.canEdit,
|
||||
),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF0FDF4),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFBBF7D0)),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.share2,
|
||||
size: 18,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -302,9 +331,11 @@ class _CalendarEventDetailScreenState extends State<CalendarEventDetailScreen> {
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await sl<CalendarService>().deleteEvent(widget.eventId);
|
||||
await sl<LocalNotificationService>().cancelEventReminder(
|
||||
widget.eventId,
|
||||
);
|
||||
try {
|
||||
await sl<LocalNotificationService>().cancelEventReminder(
|
||||
widget.eventId,
|
||||
);
|
||||
} catch (_) {}
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
import 'package:flutter/material.dart' hide BackButton;
|
||||
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../data/calendar_api.dart';
|
||||
|
||||
class CalendarShareDialog extends StatefulWidget {
|
||||
final String eventId;
|
||||
final String eventTitle;
|
||||
final bool canInvite;
|
||||
final bool canEdit;
|
||||
|
||||
const CalendarShareDialog({
|
||||
super.key,
|
||||
required this.eventId,
|
||||
required this.eventTitle,
|
||||
this.canInvite = false,
|
||||
this.canEdit = false,
|
||||
});
|
||||
|
||||
static Future<void> show(
|
||||
BuildContext context,
|
||||
String eventId,
|
||||
String eventTitle, {
|
||||
bool canInvite = false,
|
||||
bool canEdit = false,
|
||||
}) {
|
||||
return showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) => CalendarShareDialog(
|
||||
eventId: eventId,
|
||||
eventTitle: eventTitle,
|
||||
canInvite: canInvite,
|
||||
canEdit: canEdit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<CalendarShareDialog> createState() => _CalendarShareDialogState();
|
||||
}
|
||||
|
||||
class _CalendarShareDialogState extends State<CalendarShareDialog> {
|
||||
final _emailController = TextEditingController();
|
||||
bool _permissionView = true;
|
||||
bool _permissionEdit = false;
|
||||
bool _permissionInvite = false;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _handleShare() async {
|
||||
final email = _emailController.text.trim();
|
||||
if (email.isEmpty) {
|
||||
Toast.show(context, '请输入邮箱地址', type: ToastType.error);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final api = sl<CalendarApi>();
|
||||
await api.share(
|
||||
widget.eventId,
|
||||
email: email,
|
||||
view: _permissionView,
|
||||
edit: _permissionEdit,
|
||||
invite: _permissionInvite,
|
||||
);
|
||||
if (mounted) {
|
||||
Toast.show(context, '邀请已发送', type: ToastType.success);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '发送邀请失败', type: ToastType.error);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(AppRadius.lg),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'分享日历',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Text(widget.eventTitle, style: const TextStyle(fontSize: 16)),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
TextField(
|
||||
controller: _emailController,
|
||||
decoration: InputDecoration(
|
||||
labelText: '邮箱地址',
|
||||
hintText: '输入对方的邮箱',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
),
|
||||
),
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
const Text('权限设置', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildPermissionSwitch('查看', '可以查看此日历事件(必选)', true, null),
|
||||
_buildPermissionSwitch(
|
||||
'编辑',
|
||||
'可以编辑此日历事件',
|
||||
_permissionEdit,
|
||||
widget.canEdit
|
||||
? (v) => setState(() => _permissionEdit = v)
|
||||
: null,
|
||||
),
|
||||
_buildPermissionSwitch(
|
||||
'邀请',
|
||||
'可以邀请其他人',
|
||||
_permissionInvite,
|
||||
widget.canInvite
|
||||
? (v) => setState(() => _permissionInvite = v)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
AppButton(
|
||||
text: '发送邀请',
|
||||
onPressed: _isLoading ? null : _handleShare,
|
||||
isLoading: _isLoading,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPermissionSwitch(
|
||||
String title,
|
||||
String description,
|
||||
bool value,
|
||||
ValueChanged<bool>? onChanged,
|
||||
) {
|
||||
final enabled = onChanged != null;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(color: enabled ? null : Colors.grey),
|
||||
),
|
||||
Text(
|
||||
description,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: enabled ? Colors.grey : Colors.grey.shade400,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Switch(value: value, onChanged: enabled ? onChanged : null),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -98,8 +98,6 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
_endDate = now;
|
||||
_endTime = now.add(const Duration(hours: 1));
|
||||
}
|
||||
|
||||
_titleController.addListener(() => setState(() {}));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -163,18 +161,23 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: _saveEvent,
|
||||
child: Text(
|
||||
'保存',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _titleController.text.trim().isNotEmpty
|
||||
? AppColors.blue600
|
||||
: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: _titleController,
|
||||
builder: (context, value, child) {
|
||||
return GestureDetector(
|
||||
onTap: _saveEvent,
|
||||
child: Text(
|
||||
'保存',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: value.text.trim().isNotEmpty
|
||||
? AppColors.blue600
|
||||
: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -233,9 +236,10 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
if (endDateTime.isBefore(startDateTime)) {
|
||||
if (endDateTime.isBefore(startDateTime) ||
|
||||
endDateTime.isAtSameMomentAs(startDateTime)) {
|
||||
_endDate = date;
|
||||
_endTime = time;
|
||||
_endTime = time.add(const Duration(hours: 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -261,9 +265,10 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
if (endDateTime.isBefore(startDateTime)) {
|
||||
if (endDateTime.isBefore(startDateTime) ||
|
||||
endDateTime.isAtSameMomentAs(startDateTime)) {
|
||||
_endDate = _startDate;
|
||||
_endTime = _startTime;
|
||||
_endTime = _startTime.add(const Duration(hours: 1));
|
||||
} else {
|
||||
_endDate = date;
|
||||
_endTime = time;
|
||||
@@ -271,6 +276,13 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
});
|
||||
},
|
||||
isOptional: true,
|
||||
minTime: DateTime(
|
||||
_startDate.year,
|
||||
_startDate.month,
|
||||
_startDate.day,
|
||||
_startTime.hour,
|
||||
_startTime.minute,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -620,6 +632,7 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
DateTime time,
|
||||
Function(DateTime, DateTime) onChanged, {
|
||||
bool isOptional = false,
|
||||
DateTime? minTime,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -635,7 +648,7 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
const SizedBox(height: 8),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
final picked = await _pickDateTime(date, time);
|
||||
final picked = await _pickDateTime(date, time, minTime: minTime);
|
||||
if (picked == null) {
|
||||
return;
|
||||
}
|
||||
@@ -687,14 +700,18 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
|
||||
Future<(DateTime, DateTime)?> _pickDateTime(
|
||||
DateTime date,
|
||||
DateTime time,
|
||||
) async {
|
||||
DateTime time, {
|
||||
DateTime? minTime,
|
||||
}) async {
|
||||
final result = await showModalBottomSheet<(DateTime, DateTime)>(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
isScrollControlled: true,
|
||||
builder: (context) =>
|
||||
_DateTimePickerSheet(initialDate: date, initialTime: time),
|
||||
builder: (context) => _DateTimePickerSheet(
|
||||
initialDate: date,
|
||||
initialTime: time,
|
||||
minTime: minTime,
|
||||
),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@@ -845,6 +862,7 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
id: _isEditing
|
||||
? widget.editingEvent!.id
|
||||
: 'evt_${DateTime.now().millisecondsSinceEpoch}',
|
||||
ownerId: widget.editingEvent?.ownerId ?? '',
|
||||
title: _titleController.text.trim(),
|
||||
description: _descriptionController.text.trim().isNotEmpty
|
||||
? _descriptionController.text.trim()
|
||||
@@ -856,7 +874,6 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
|
||||
try {
|
||||
final service = sl<CalendarService>();
|
||||
final notificationService = sl<LocalNotificationService>();
|
||||
late final ScheduleItemModel saved;
|
||||
|
||||
if (_isEditing) {
|
||||
@@ -864,7 +881,11 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
} else {
|
||||
saved = await service.addEvent(event);
|
||||
}
|
||||
await notificationService.upsertEventReminder(saved);
|
||||
|
||||
try {
|
||||
final notificationService = sl<LocalNotificationService>();
|
||||
await notificationService.upsertEventReminder(saved);
|
||||
} catch (_) {}
|
||||
|
||||
widget.onSaved?.call();
|
||||
if (mounted) {
|
||||
@@ -889,10 +910,12 @@ class _CreateEventSheetState extends State<CreateEventSheet>
|
||||
class _DateTimePickerSheet extends StatefulWidget {
|
||||
final DateTime initialDate;
|
||||
final DateTime initialTime;
|
||||
final DateTime? minTime;
|
||||
|
||||
const _DateTimePickerSheet({
|
||||
required this.initialDate,
|
||||
required this.initialTime,
|
||||
this.minTime,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -915,10 +938,49 @@ class _DateTimePickerSheetState extends State<_DateTimePickerSheet> {
|
||||
static final int _baseYear = DateTime.now().year;
|
||||
static final List<int> _years = List.generate(21, (i) => _baseYear - 10 + i);
|
||||
static final List<int> _months = List.generate(12, (i) => i + 1);
|
||||
static final List<int> _hours = List.generate(24, (i) => i);
|
||||
static final List<int> _minutes = List.generate(60, (i) => i);
|
||||
static final List<int> _allHours = List.generate(24, (i) => i);
|
||||
static final List<int> _allMinutes = List.generate(60, (i) => i);
|
||||
|
||||
List<int> _days = [];
|
||||
late List<int> _filteredHours;
|
||||
late List<int> _filteredMinutes;
|
||||
|
||||
List<int> _getFilteredHours() {
|
||||
if (widget.minTime == null) return _allHours;
|
||||
final minDate = widget.minTime!;
|
||||
if (_selectedYear > minDate.year ||
|
||||
(_selectedYear == minDate.year && _selectedMonth > minDate.month) ||
|
||||
(_selectedYear == minDate.year &&
|
||||
_selectedMonth == minDate.month &&
|
||||
_selectedDay > minDate.day)) {
|
||||
return _allHours;
|
||||
}
|
||||
if (_selectedYear == minDate.year &&
|
||||
_selectedMonth == minDate.month &&
|
||||
_selectedDay == minDate.day) {
|
||||
return _allHours.where((h) => h > minDate.hour).toList();
|
||||
}
|
||||
return _allHours;
|
||||
}
|
||||
|
||||
List<int> _getFilteredMinutes() {
|
||||
if (widget.minTime == null) return _allMinutes;
|
||||
final minDate = widget.minTime!;
|
||||
if (_selectedYear > minDate.year ||
|
||||
(_selectedYear == minDate.year && _selectedMonth > minDate.month) ||
|
||||
(_selectedYear == minDate.year &&
|
||||
_selectedMonth == minDate.month &&
|
||||
_selectedDay > minDate.day)) {
|
||||
return _allMinutes;
|
||||
}
|
||||
if (_selectedYear == minDate.year &&
|
||||
_selectedMonth == minDate.month &&
|
||||
_selectedDay == minDate.day &&
|
||||
_selectedHour == minDate.hour) {
|
||||
return _allMinutes.where((m) => m > minDate.minute).toList();
|
||||
}
|
||||
return _allMinutes;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -928,6 +990,8 @@ class _DateTimePickerSheetState extends State<_DateTimePickerSheet> {
|
||||
_selectedDay = widget.initialDate.day;
|
||||
_selectedHour = widget.initialTime.hour;
|
||||
_selectedMinute = widget.initialTime.minute;
|
||||
_filteredHours = _getFilteredHours();
|
||||
_filteredMinutes = _getFilteredMinutes();
|
||||
_updateDays();
|
||||
|
||||
_yearController = FixedExtentScrollController(
|
||||
@@ -937,9 +1001,11 @@ class _DateTimePickerSheetState extends State<_DateTimePickerSheet> {
|
||||
initialItem: _selectedMonth - 1,
|
||||
);
|
||||
_dayController = FixedExtentScrollController(initialItem: _selectedDay - 1);
|
||||
_hourController = FixedExtentScrollController(initialItem: _selectedHour);
|
||||
_hourController = FixedExtentScrollController(
|
||||
initialItem: _filteredHours.indexOf(_selectedHour),
|
||||
);
|
||||
_minuteController = FixedExtentScrollController(
|
||||
initialItem: _selectedMinute,
|
||||
initialItem: _filteredMinutes.indexOf(_selectedMinute),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1055,9 +1121,26 @@ class _DateTimePickerSheetState extends State<_DateTimePickerSheet> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildPicker(
|
||||
_hours,
|
||||
_filteredHours,
|
||||
_hourController,
|
||||
(v) => setState(() => _selectedHour = v),
|
||||
(v) {
|
||||
setState(() {
|
||||
_selectedHour = v;
|
||||
_filteredMinutes = _getFilteredMinutes();
|
||||
if (_selectedMinute >
|
||||
_filteredMinutes.last) {
|
||||
_selectedMinute =
|
||||
_filteredMinutes.isNotEmpty
|
||||
? _filteredMinutes.last
|
||||
: 0;
|
||||
_minuteController.jumpToItem(
|
||||
_filteredMinutes.indexOf(
|
||||
_selectedMinute,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
(v) => v.toString().padLeft(2, '0'),
|
||||
itemExtent: 50,
|
||||
),
|
||||
@@ -1072,7 +1155,7 @@ class _DateTimePickerSheetState extends State<_DateTimePickerSheet> {
|
||||
),
|
||||
Expanded(
|
||||
child: _buildPicker(
|
||||
_minutes,
|
||||
_filteredMinutes,
|
||||
_minuteController,
|
||||
(v) => setState(() => _selectedMinute = v),
|
||||
(v) => v.toString().padLeft(2, '0'),
|
||||
|
||||
@@ -671,13 +671,13 @@ class _HomeScreenState extends State<HomeScreen>
|
||||
)
|
||||
: Icon(
|
||||
key: _inputActionIconKey,
|
||||
_isRecording || isWaitingAgent
|
||||
isWaitingAgent
|
||||
? LucideIcons.square
|
||||
: _hasMessage
|
||||
: _isRecording || _hasMessage
|
||||
? LucideIcons.send
|
||||
: LucideIcons.mic,
|
||||
size: _iconSize,
|
||||
color: _isRecording || isWaitingAgent || _hasMessage
|
||||
color: isWaitingAgent || _isRecording || _hasMessage
|
||||
? AppColors.blue600
|
||||
: AppColors.slate500,
|
||||
),
|
||||
|
||||
@@ -8,8 +8,11 @@ import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/page_header.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../calendar/data/calendar_api.dart';
|
||||
import '../../../friends/data/friends_api.dart';
|
||||
import '../../data/inbox_api.dart';
|
||||
import '../../ui/widgets/calendar_message_card.dart';
|
||||
|
||||
class MessageWithFriend {
|
||||
final InboxMessageResponse message;
|
||||
@@ -29,6 +32,7 @@ class MessageInviteListScreen extends StatefulWidget {
|
||||
class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
late final InboxApi _inboxApi;
|
||||
late final FriendsApi _friendsApi;
|
||||
late final CalendarApi _calendarApi;
|
||||
|
||||
List<MessageWithFriend> _unreadMessages = [];
|
||||
List<MessageWithFriend> _readMessages = [];
|
||||
@@ -40,6 +44,7 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
super.initState();
|
||||
_inboxApi = sl<InboxApi>();
|
||||
_friendsApi = sl<FriendsApi>();
|
||||
_calendarApi = sl<CalendarApi>();
|
||||
_loadMessages();
|
||||
}
|
||||
|
||||
@@ -103,7 +108,23 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
final message = item.message;
|
||||
switch (message.messageType) {
|
||||
case InboxMessageType.calendar:
|
||||
context.push('/messages/invites/${message.id}');
|
||||
final content = _parseCalendarContent(message.content);
|
||||
if (content == null) return;
|
||||
|
||||
final type = content['type'] as String?;
|
||||
if (type == 'invite') {
|
||||
if (message.status.value == 'pending') {
|
||||
await _showCalendarInviteSheet(message);
|
||||
} else if (message.status.value == 'accepted') {
|
||||
if (message.scheduleItemId != null) {
|
||||
context.push('/calendar/${message.scheduleItemId}');
|
||||
}
|
||||
}
|
||||
} else if (type == 'update') {
|
||||
if (message.scheduleItemId != null) {
|
||||
context.push('/calendar/${message.scheduleItemId}');
|
||||
}
|
||||
}
|
||||
return;
|
||||
case InboxMessageType.friendRequest:
|
||||
if (item.friendRequest == null) {
|
||||
@@ -122,6 +143,91 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic>? _parseCalendarContent(String? content) {
|
||||
if (content == null) return null;
|
||||
try {
|
||||
return jsonDecode(content) as Map<String, dynamic>;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showCalendarInviteSheet(InboxMessageResponse message) async {
|
||||
final itemId = message.scheduleItemId;
|
||||
if (itemId == null) return;
|
||||
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (ctx) => Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(AppRadius.lg),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'日历邀请',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppButton(
|
||||
text: '拒绝',
|
||||
isOutlined: true,
|
||||
onPressed: () async {
|
||||
try {
|
||||
await _calendarApi.rejectSubscription(itemId);
|
||||
await _inboxApi.markAsRead(message.id);
|
||||
if (mounted) {
|
||||
Navigator.pop(ctx);
|
||||
Toast.show(context, '已拒绝', type: ToastType.success);
|
||||
_loadMessages();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '操作失败', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: AppButton(
|
||||
text: '接受',
|
||||
onPressed: () async {
|
||||
try {
|
||||
await _calendarApi.acceptSubscription(itemId);
|
||||
await _inboxApi.markAsRead(message.id);
|
||||
if (mounted) {
|
||||
Navigator.pop(ctx);
|
||||
Toast.show(context, '已接受', type: ToastType.success);
|
||||
_loadMessages();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '操作失败', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showFriendRequestReadOnlySheet(MessageWithFriend item) {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
@@ -465,7 +571,35 @@ class _MessageCard extends StatelessWidget {
|
||||
return '系统消息';
|
||||
}
|
||||
|
||||
String _content() => message.content ?? '点击查看详情';
|
||||
String _content() {
|
||||
if (message.messageType == InboxMessageType.calendar) {
|
||||
Map<String, dynamic>? data;
|
||||
if (message.content != null) {
|
||||
try {
|
||||
data = jsonDecode(message.content!) as Map<String, dynamic>;
|
||||
} catch (_) {
|
||||
data = null;
|
||||
}
|
||||
}
|
||||
if (data == null) return '点击查看详情';
|
||||
|
||||
final type = data['type'] as String?;
|
||||
if (type == 'invite') {
|
||||
final status = message.status.value;
|
||||
if (status == 'pending') {
|
||||
return '邀请您加入日历';
|
||||
} else if (status == 'accepted') {
|
||||
return '已接受日历邀请';
|
||||
} else if (status == 'rejected') {
|
||||
return '已拒绝日历邀请';
|
||||
}
|
||||
} else if (type == 'update') {
|
||||
return '更新了日历事件';
|
||||
}
|
||||
return '点击查看详情';
|
||||
}
|
||||
return message.content ?? '点击查看详情';
|
||||
}
|
||||
}
|
||||
|
||||
class _FriendRequestSheet extends StatelessWidget {
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../data/inbox_api.dart';
|
||||
|
||||
class CalendarInviteCard extends StatelessWidget {
|
||||
final InboxMessageResponse message;
|
||||
final VoidCallback onAccept;
|
||||
final VoidCallback onReject;
|
||||
|
||||
const CalendarInviteCard({
|
||||
super.key,
|
||||
required this.message,
|
||||
required this.onAccept,
|
||||
required this.onReject,
|
||||
});
|
||||
|
||||
String? get eventTitle {
|
||||
if (message.content == null) return null;
|
||||
try {
|
||||
final data = jsonDecode(message.content!) as Map<String, dynamic>;
|
||||
return data['title'] as String?;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.xs,
|
||||
),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue100,
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.calendar_today,
|
||||
color: AppColors.blue600,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'日历邀请',
|
||||
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text(
|
||||
eventTitle != null ? '邀请你访问 "$eventTitle"' : '邀请你访问日历',
|
||||
style: const TextStyle(fontSize: 14, color: AppColors.slate700),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppButton(
|
||||
text: '拒绝',
|
||||
isOutlined: true,
|
||||
onPressed: onReject,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: AppButton(text: '接受', onPressed: onAccept),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CalendarUpdateCard extends StatelessWidget {
|
||||
final InboxMessageResponse message;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const CalendarUpdateCard({super.key, required this.message, this.onTap});
|
||||
|
||||
String? get eventTitle {
|
||||
if (message.content == null) return null;
|
||||
try {
|
||||
final data = jsonDecode(message.content!) as Map<String, dynamic>;
|
||||
return data['title'] as String?;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.xs,
|
||||
),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue100,
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.calendar_today,
|
||||
color: AppColors.blue600,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
eventTitle != null ? '$eventTitle 已更新' : '日历事件已更新',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
_formatTime(message.createdAt),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: AppColors.slate400),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatTime(DateTime time) {
|
||||
final now = DateTime.now();
|
||||
final diff = now.difference(time);
|
||||
if (diff.inMinutes < 60) {
|
||||
return '${diff.inMinutes}分钟前';
|
||||
} else if (diff.inHours < 24) {
|
||||
return '${diff.inHours}小时前';
|
||||
} else if (diff.inDays < 7) {
|
||||
return '${diff.inDays}天前';
|
||||
} else {
|
||||
return '${time.month}月${time.day}日';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CalendarDeleteCard extends StatelessWidget {
|
||||
final InboxMessageResponse message;
|
||||
|
||||
const CalendarDeleteCard({super.key, required this.message});
|
||||
|
||||
String? get eventTitle {
|
||||
if (message.content == null) return null;
|
||||
try {
|
||||
final data = jsonDecode(message.content!) as Map<String, dynamic>;
|
||||
return data['title'] as String?;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.xs,
|
||||
),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.slate200),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate200,
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.calendar_today,
|
||||
color: AppColors.slate500,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
eventTitle != null ? '$eventTitle 已删除' : '日历事件已删除',
|
||||
style: const TextStyle(fontSize: 14, color: AppColors.slate500),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
import 'package:social_app/core/api/i_api_client.dart';
|
||||
|
||||
class TodoApi {
|
||||
final IApiClient _client;
|
||||
static const _prefix = '/api/v1/todos';
|
||||
|
||||
TodoApi(this._client);
|
||||
|
||||
Future<List<TodoResponse>> getTodos({String? status, int? priority}) async {
|
||||
final queryParts = <String>[];
|
||||
if (status != null) queryParts.add('status=$status');
|
||||
if (priority != null) queryParts.add('priority=$priority');
|
||||
final query = queryParts.isEmpty ? '' : '?${queryParts.join('&')}';
|
||||
|
||||
final response = await _client.get('$_prefix$query');
|
||||
final List<dynamic> data = response.data;
|
||||
return data.map((json) => TodoResponse.fromJson(json)).toList();
|
||||
}
|
||||
|
||||
Future<TodoResponse> getTodo(String id) async {
|
||||
final response = await _client.get('$_prefix/$id');
|
||||
return TodoResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<TodoResponse> createTodo({
|
||||
required String title,
|
||||
String? description,
|
||||
DateTime? dueAt,
|
||||
int priority = 1,
|
||||
List<String> scheduleItemIds = const [],
|
||||
}) async {
|
||||
final data = <String, dynamic>{'title': title, 'priority': priority};
|
||||
if (description != null) data['description'] = description;
|
||||
if (dueAt != null) data['due_at'] = dueAt.toIso8601String();
|
||||
if (scheduleItemIds.isNotEmpty) data['schedule_item_ids'] = scheduleItemIds;
|
||||
|
||||
final response = await _client.post(_prefix, data: data);
|
||||
return TodoResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<TodoResponse> updateTodo(
|
||||
String id, {
|
||||
String? title,
|
||||
String? description,
|
||||
DateTime? dueAt,
|
||||
int? priority,
|
||||
String? status,
|
||||
List<String>? scheduleItemIds,
|
||||
}) async {
|
||||
final data = <String, dynamic>{};
|
||||
if (title != null) data['title'] = title;
|
||||
if (description != null) data['description'] = description;
|
||||
if (dueAt != null) data['due_at'] = dueAt.toIso8601String();
|
||||
if (priority != null) data['priority'] = priority;
|
||||
if (status != null) data['status'] = status;
|
||||
if (scheduleItemIds != null) data['schedule_item_ids'] = scheduleItemIds;
|
||||
|
||||
final response = await _client.patch('$_prefix/$id', data: data);
|
||||
return TodoResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<TodoResponse> completeTodo(String id) async {
|
||||
final response = await _client.post('$_prefix/$id/complete', data: {});
|
||||
return TodoResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<void> deleteTodo(String id) async {
|
||||
await _client.delete('$_prefix/$id');
|
||||
}
|
||||
}
|
||||
|
||||
class ScheduleItemBasic {
|
||||
final String id;
|
||||
final String title;
|
||||
final DateTime startAt;
|
||||
final DateTime? endAt;
|
||||
|
||||
ScheduleItemBasic({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.startAt,
|
||||
this.endAt,
|
||||
});
|
||||
|
||||
factory ScheduleItemBasic.fromJson(Map<String, dynamic> json) {
|
||||
return ScheduleItemBasic(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
startAt: DateTime.parse(json['start_at'] as String),
|
||||
endAt: json['end_at'] != null
|
||||
? DateTime.parse(json['end_at'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TodoResponse {
|
||||
final String id;
|
||||
final String ownerId;
|
||||
final String title;
|
||||
final String? description;
|
||||
final DateTime? dueAt;
|
||||
final int priority;
|
||||
final String status;
|
||||
final DateTime? completedAt;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final List<ScheduleItemBasic> scheduleItems;
|
||||
|
||||
TodoResponse({
|
||||
required this.id,
|
||||
required this.ownerId,
|
||||
required this.title,
|
||||
this.description,
|
||||
this.dueAt,
|
||||
required this.priority,
|
||||
required this.status,
|
||||
this.completedAt,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
this.scheduleItems = const [],
|
||||
});
|
||||
|
||||
factory TodoResponse.fromJson(Map<String, dynamic> json) {
|
||||
final scheduleItemsList = json['schedule_items'] as List<dynamic>? ?? [];
|
||||
return TodoResponse(
|
||||
id: json['id'] as String,
|
||||
ownerId: json['owner_id'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String?,
|
||||
dueAt: json['due_at'] != null
|
||||
? DateTime.parse(json['due_at'] as String)
|
||||
: null,
|
||||
priority: json['priority'] as int,
|
||||
status: json['status'] as String,
|
||||
completedAt: json['completed_at'] != null
|
||||
? DateTime.parse(json['completed_at'] as String)
|
||||
: null,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
scheduleItems: scheduleItemsList
|
||||
.map((e) => ScheduleItemBasic.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
TodoResponse copyWith({
|
||||
String? id,
|
||||
String? ownerId,
|
||||
String? title,
|
||||
String? description,
|
||||
DateTime? dueAt,
|
||||
int? priority,
|
||||
String? status,
|
||||
DateTime? completedAt,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
List<ScheduleItemBasic>? scheduleItems,
|
||||
}) {
|
||||
return TodoResponse(
|
||||
id: id ?? this.id,
|
||||
ownerId: ownerId ?? this.ownerId,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
dueAt: dueAt ?? this.dueAt,
|
||||
priority: priority ?? this.priority,
|
||||
status: status ?? this.status,
|
||||
completedAt: completedAt ?? this.completedAt,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
scheduleItems: scheduleItems ?? this.scheduleItems,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../../calendar/data/calendar_api.dart';
|
||||
import '../../data/todo_api.dart';
|
||||
|
||||
class TodoDetailScreen extends StatelessWidget {
|
||||
const TodoDetailScreen({super.key});
|
||||
class TodoDetailScreen extends StatefulWidget {
|
||||
final String todoId;
|
||||
|
||||
const TodoDetailScreen({super.key, required this.todoId});
|
||||
|
||||
@override
|
||||
State<TodoDetailScreen> createState() => _TodoDetailScreenState();
|
||||
}
|
||||
|
||||
class _TodoDetailScreenState extends State<TodoDetailScreen> {
|
||||
final TodoApi _todoApi = sl<TodoApi>();
|
||||
|
||||
TodoResponse? _todo;
|
||||
bool _isLoading = true;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadTodo();
|
||||
}
|
||||
|
||||
Future<void> _loadTodo() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final todo = await _todoApi.getTodo(widget.todoId);
|
||||
setState(() {
|
||||
_todo = todo;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_error = e.toString();
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
String _getPriorityLabel(int priority) {
|
||||
switch (priority) {
|
||||
case 1:
|
||||
return '重要紧急';
|
||||
case 2:
|
||||
return '重要不紧急';
|
||||
case 3:
|
||||
return '紧急不重要';
|
||||
case 4:
|
||||
return '不紧急不重要';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
|
||||
Color _getPriorityColor(int priority) {
|
||||
switch (priority) {
|
||||
case 1:
|
||||
return AppColors.g1Text;
|
||||
case 2:
|
||||
return AppColors.g3Text;
|
||||
case 3:
|
||||
return AppColors.g2Text;
|
||||
default:
|
||||
return AppColors.slate500;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -25,69 +99,118 @@ class TodoDetailScreen extends StatelessWidget {
|
||||
height: 64,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 12, bottom: 8),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.messageBtnWrap,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
border: Border.all(color: AppColors.messageBtnBorder, width: 1),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.chevronLeft,
|
||||
size: 16,
|
||||
color: AppColors.slate700,
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.messageBtnWrap,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
border: Border.all(
|
||||
color: AppColors.messageBtnBorder,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.chevronLeft,
|
||||
size: 16,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (_todo != null) ...[
|
||||
IconButton(
|
||||
onPressed: _editTodo,
|
||||
icon: const Icon(
|
||||
LucideIcons.pencil,
|
||||
size: 20,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: _deleteTodo,
|
||||
icon: const Icon(
|
||||
LucideIcons.trash2,
|
||||
size: 20,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent() {
|
||||
if (_isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (_error != null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('加载失败: $_error', style: const TextStyle(color: Colors.red)),
|
||||
const SizedBox(height: 16),
|
||||
AppButton(text: '重试', onPressed: _loadTodo),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_todo == null) {
|
||||
return const Center(child: Text('待办不存在'));
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 20),
|
||||
child: ListView(
|
||||
children: [
|
||||
_buildMainCard(),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'日历事件卡片',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
if (_todo!.scheduleItems.isNotEmpty) ...[
|
||||
Text(
|
||||
'日历事件卡片',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildEventCard(
|
||||
title: '完成活动海报设计',
|
||||
time: '2026年2月9日 09:00 - 09:30',
|
||||
borderColor: AppColors.todoEventBorder1,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildEventCard(
|
||||
title: '活动方案评审会议',
|
||||
time: '2026年2月9日 16:00 - 17:00',
|
||||
borderColor: AppColors.todoEventBorder2,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildEventCard(
|
||||
title: '提交最终活动方案',
|
||||
time: '2026年2月10日 10:00 - 10:20',
|
||||
borderColor: AppColors.todoEventBorder3,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
..._todo!.scheduleItems.map(
|
||||
(item) => _buildEventCard(
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
time: _formatEventTime(item.startAt, item.endAt),
|
||||
borderColor: AppColors.todoEventBorder1,
|
||||
onTap: () => context.push('/calendar/events/${item.id}'),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatEventTime(DateTime start, DateTime? end) {
|
||||
final startStr =
|
||||
'${start.year}年${start.month}月${start.day}日 ${start.hour.toString().padLeft(2, '0')}:${start.minute.toString().padLeft(2, '0')}';
|
||||
if (end != null) {
|
||||
final endStr =
|
||||
'${end.hour.toString().padLeft(2, '0')}:${end.minute.toString().padLeft(2, '0')}';
|
||||
return '$startStr - $endStr';
|
||||
}
|
||||
return startStr;
|
||||
}
|
||||
|
||||
Widget _buildMainCard() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
@@ -100,9 +223,9 @@ class TodoDetailScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'活动发布准备',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
_todo!.title,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
@@ -110,34 +233,69 @@ class TodoDetailScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(
|
||||
'截止今天 18:00 · 已拆分为多个日历事件',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
_buildSubtitle(),
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
if (_todo!.description != null && _todo!.description!.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_todo!.description!,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 13,
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
Container(height: 1, color: const Color(0xFFE5E7EB)),
|
||||
Container(height: 1, color: AppColors.border),
|
||||
const SizedBox(height: 8),
|
||||
_buildInfoRow(
|
||||
label: '所属象限',
|
||||
value: '重要紧急',
|
||||
valueColor: AppColors.g1Text,
|
||||
value: _getPriorityLabel(_todo!.priority),
|
||||
valueColor: _getPriorityColor(_todo!.priority),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildInfoRow(
|
||||
label: '关联日历事件',
|
||||
value: '3个',
|
||||
value: '${_todo!.scheduleItems.length}个',
|
||||
valueColor: AppColors.g3Text,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildInfoRow(
|
||||
label: '状态',
|
||||
value: _todo!.status == 'done' ? '已完成' : '进行中',
|
||||
valueColor: _todo!.status == 'done'
|
||||
? AppColors.success
|
||||
: AppColors.blue600,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _buildSubtitle() {
|
||||
final parts = <String>[];
|
||||
if (_todo!.dueAt != null) {
|
||||
final due = _todo!.dueAt!;
|
||||
parts.add(
|
||||
'截止 ${due.month}月${due.day}日 ${due.hour.toString().padLeft(2, '0')}:${due.minute.toString().padLeft(2, '0')}',
|
||||
);
|
||||
}
|
||||
if (_todo!.scheduleItems.isNotEmpty) {
|
||||
parts.add('已拆分为${_todo!.scheduleItems.length}个日历事件');
|
||||
} else {
|
||||
parts.add('未关联日历事件');
|
||||
}
|
||||
return parts.join(' · ');
|
||||
}
|
||||
|
||||
Widget _buildInfoRow({
|
||||
required String label,
|
||||
required String value,
|
||||
@@ -169,69 +327,365 @@ class TodoDetailScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildEventCard({
|
||||
required String id,
|
||||
required String title,
|
||||
required String time,
|
||||
required Color borderColor,
|
||||
VoidCallback? onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.todoCardBg,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: borderColor, width: 1),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
time,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _editTodo() async {
|
||||
final result = await showModalBottomSheet<Map<String, dynamic>>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) => _EditTodoSheet(todo: _todo!),
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
try {
|
||||
await _todoApi.updateTodo(
|
||||
_todo!.id,
|
||||
title: result['title'] as String,
|
||||
description: result['description'] as String?,
|
||||
priority: result['priority'] as int,
|
||||
scheduleItemIds: result['schedule_item_ids'] as List<String>?,
|
||||
);
|
||||
await _loadTodo();
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '更新失败: $e', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _deleteTodo() async {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('确认删除'),
|
||||
content: const Text('确定要删除这个待办吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('删除', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirm == true) {
|
||||
try {
|
||||
await _todoApi.deleteTodo(_todo!.id);
|
||||
if (mounted) {
|
||||
context.pop();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '删除失败: $e', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _EditTodoSheet extends StatefulWidget {
|
||||
final TodoResponse todo;
|
||||
|
||||
const _EditTodoSheet({required this.todo});
|
||||
|
||||
@override
|
||||
State<_EditTodoSheet> createState() => _EditTodoSheetState();
|
||||
}
|
||||
|
||||
class _EditTodoSheetState extends State<_EditTodoSheet> {
|
||||
late TextEditingController _titleController;
|
||||
late TextEditingController _descriptionController;
|
||||
late int _priority;
|
||||
late Set<String> _selectedScheduleItems;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_titleController = TextEditingController(text: widget.todo.title);
|
||||
_descriptionController = TextEditingController(
|
||||
text: widget.todo.description ?? '',
|
||||
);
|
||||
_priority = widget.todo.priority;
|
||||
_selectedScheduleItems = widget.todo.scheduleItems.map((e) => e.id).toSet();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_titleController.dispose();
|
||||
_descriptionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.todoCardBg,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: borderColor, width: 1),
|
||||
height: MediaQuery.of(context).size.height * 0.85,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'编辑待办',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(LucideIcons.x),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate300,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
controller: _titleController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '标题',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate300,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _descriptionController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '描述(可选)',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
maxLines: 2,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'优先级',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
_PriorityChip(
|
||||
label: '重要紧急',
|
||||
selected: _priority == 1,
|
||||
color: AppColors.g1Border,
|
||||
onTap: () => setState(() => _priority = 1),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_PriorityChip(
|
||||
label: '紧急不重要',
|
||||
selected: _priority == 3,
|
||||
color: AppColors.g2Border,
|
||||
onTap: () => setState(() => _priority = 3),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_PriorityChip(
|
||||
label: '重要不紧急',
|
||||
selected: _priority == 2,
|
||||
color: AppColors.g3Border,
|
||||
onTap: () => setState(() => _priority = 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
time,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
Expanded(
|
||||
child: FutureBuilder(
|
||||
future: _loadScheduleItems(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Center(child: Text('加载失败: ${snapshot.error}'));
|
||||
}
|
||||
final items = snapshot.data ?? [];
|
||||
if (items.isEmpty) {
|
||||
return const Center(child: Text('暂无日历事件'));
|
||||
}
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
final isSelected = _selectedScheduleItems.contains(item.id);
|
||||
return CheckboxListTile(
|
||||
title: Text(item.title),
|
||||
subtitle: Text(_formatDate(item.startAt)),
|
||||
value: isSelected,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
if (value == true) {
|
||||
_selectedScheduleItems.add(item.id);
|
||||
} else {
|
||||
_selectedScheduleItems.remove(item.id);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: AppButton(
|
||||
text: '保存',
|
||||
onPressed: () {
|
||||
if (_titleController.text.trim().isEmpty) {
|
||||
Toast.show(context, '请输入标题', type: ToastType.warning);
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pop({
|
||||
'title': _titleController.text.trim(),
|
||||
'description': _descriptionController.text.trim().isEmpty
|
||||
? null
|
||||
: _descriptionController.text.trim(),
|
||||
'priority': _priority,
|
||||
'schedule_item_ids': _selectedScheduleItems.toList(),
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<_ScheduleItemSimple>> _loadScheduleItems() async {
|
||||
final calendarApi = sl<CalendarApi>();
|
||||
final now = DateTime.now();
|
||||
final start = now.subtract(const Duration(days: 30));
|
||||
final end = now.add(const Duration(days: 90));
|
||||
final items = await calendarApi.listByRange(startAt: start, endAt: end);
|
||||
return items
|
||||
.map(
|
||||
(e) =>
|
||||
_ScheduleItemSimple(id: e.id, title: e.title, startAt: e.startAt),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
String _formatDate(DateTime dt) {
|
||||
return '${dt.year}年${dt.month}月${dt.day}日 ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
|
||||
class _ScheduleItemSimple {
|
||||
final String id;
|
||||
final String title;
|
||||
final DateTime startAt;
|
||||
|
||||
_ScheduleItemSimple({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.startAt,
|
||||
});
|
||||
}
|
||||
|
||||
class _PriorityChip extends StatelessWidget {
|
||||
final String label;
|
||||
final bool selected;
|
||||
final Color color;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _PriorityChip({
|
||||
required this.label,
|
||||
required this.selected,
|
||||
required this.color,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? color.withValues(alpha: 0.2) : Colors.transparent,
|
||||
border: Border.all(
|
||||
color: selected ? color : AppColors.slate300,
|
||||
width: selected ? 2 : 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 12,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.normal,
|
||||
color: selected ? color : AppColors.slate600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,13 @@ import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../../calendar/data/calendar_api.dart';
|
||||
import '../../../calendar/ui/calendar_state_manager.dart';
|
||||
import '../../../calendar/ui/widgets/bottom_dock.dart';
|
||||
import '../../data/todo_api.dart';
|
||||
|
||||
class TodoQuadrantsScreen extends StatefulWidget {
|
||||
const TodoQuadrantsScreen({super.key});
|
||||
@@ -13,38 +18,103 @@ class TodoQuadrantsScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
late List<_TodoItem> _importantUrgent;
|
||||
late List<_TodoItem> _urgentNotImportant;
|
||||
late List<_TodoItem> _importantNotUrgent;
|
||||
final TodoApi _todoApi = sl<TodoApi>();
|
||||
|
||||
List<TodoResponse> _todos = [];
|
||||
bool _isLoading = true;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_importantUrgent = [
|
||||
_TodoItem(title: '18:00 前提交活动方案'),
|
||||
_TodoItem(title: '回复客户邀约确认'),
|
||||
];
|
||||
_urgentNotImportant = [
|
||||
_TodoItem(title: '确认会场停车信息'),
|
||||
_TodoItem(title: '代订明早高铁票'),
|
||||
];
|
||||
_importantNotUrgent = [
|
||||
_TodoItem(title: '本周复盘与下周规划'),
|
||||
_TodoItem(title: '整理个人知识库结构'),
|
||||
_TodoItem(title: '优化三月目标里程碑'),
|
||||
];
|
||||
_loadTodos();
|
||||
}
|
||||
|
||||
void _removeItem(String id, List<_TodoItem> list) {
|
||||
Future<void> _loadTodos() async {
|
||||
setState(() {
|
||||
list.removeWhere((item) => item.id == id);
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final todos = await _todoApi.getTodos(status: 'pending');
|
||||
setState(() {
|
||||
_todos = todos;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_error = e.toString();
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
List<TodoResponse> get _importantUrgent =>
|
||||
_todos.where((t) => t.priority == 1).toList();
|
||||
|
||||
List<TodoResponse> get _urgentNotImportant =>
|
||||
_todos.where((t) => t.priority == 3).toList();
|
||||
|
||||
List<TodoResponse> get _importantNotUrgent =>
|
||||
_todos.where((t) => t.priority == 2).toList();
|
||||
|
||||
Future<void> _completeTodo(TodoResponse todo) async {
|
||||
try {
|
||||
await _todoApi.completeTodo(todo.id);
|
||||
if (mounted) {
|
||||
Toast.show(context, '已完成', type: ToastType.success);
|
||||
}
|
||||
try {
|
||||
await _loadTodos();
|
||||
} catch (_) {
|
||||
// ignore reload error
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '完成失败: $e', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _navigateToDetail(TodoResponse todo) {
|
||||
context.push('/todo/${todo.id}');
|
||||
}
|
||||
|
||||
Future<void> _addTodo() async {
|
||||
final result = await showModalBottomSheet<Map<String, dynamic>>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) => const _AddTodoSheet(),
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
try {
|
||||
await _todoApi.createTodo(
|
||||
title: result['title'] as String,
|
||||
description: result['description'] as String?,
|
||||
priority: result['priority'] as int,
|
||||
scheduleItemIds: (result['schedule_item_ids'] as List<String>?) ?? [],
|
||||
);
|
||||
await _loadTodos();
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Toast.show(context, '创建失败: $e', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.todoBg,
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _addTodo,
|
||||
backgroundColor: AppColors.blue600,
|
||||
child: const Icon(Icons.add, color: Colors.white),
|
||||
),
|
||||
body: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
@@ -70,54 +140,83 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
height: 72,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 14, bottom: 8),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: const Text(
|
||||
'待办事项',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'待办事项',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: _loadTodos,
|
||||
icon: const Icon(Icons.refresh, color: AppColors.slate600),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 96),
|
||||
child: ListView(
|
||||
children: [
|
||||
_buildQuadrant(
|
||||
title: '重要紧急',
|
||||
textColor: AppColors.g1Text,
|
||||
dividerColor: AppColors.g1Divider,
|
||||
borderColor: AppColors.g1Border,
|
||||
items: _importantUrgent,
|
||||
onRemove: (id) => _removeItem(id, _importantUrgent),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildQuadrant(
|
||||
title: '紧急不重要',
|
||||
textColor: AppColors.g2Text,
|
||||
dividerColor: AppColors.g2Divider,
|
||||
borderColor: AppColors.g2Border,
|
||||
items: _urgentNotImportant,
|
||||
onRemove: (id) => _removeItem(id, _urgentNotImportant),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildQuadrant(
|
||||
title: '重要不紧急',
|
||||
textColor: AppColors.g3Text,
|
||||
dividerColor: AppColors.g3Divider,
|
||||
borderColor: AppColors.g3Border,
|
||||
items: _importantNotUrgent,
|
||||
onRemove: (id) => _removeItem(id, _importantNotUrgent),
|
||||
),
|
||||
],
|
||||
if (_isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (_error != null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('加载失败: $_error', style: const TextStyle(color: Colors.red)),
|
||||
const SizedBox(height: 16),
|
||||
AppButton(text: '重试', onPressed: _loadTodos),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: _loadTodos,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 96),
|
||||
child: ListView(
|
||||
children: [
|
||||
_buildQuadrant(
|
||||
title: '重要紧急',
|
||||
textColor: AppColors.g1Text,
|
||||
dividerColor: AppColors.g1Divider,
|
||||
borderColor: AppColors.g1Border,
|
||||
items: _importantUrgent,
|
||||
onComplete: _completeTodo,
|
||||
onTap: _navigateToDetail,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildQuadrant(
|
||||
title: '紧急不重要',
|
||||
textColor: AppColors.g2Text,
|
||||
dividerColor: AppColors.g2Divider,
|
||||
borderColor: AppColors.g2Border,
|
||||
items: _urgentNotImportant,
|
||||
onComplete: _completeTodo,
|
||||
onTap: _navigateToDetail,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildQuadrant(
|
||||
title: '重要不紧急',
|
||||
textColor: AppColors.g3Text,
|
||||
dividerColor: AppColors.g3Divider,
|
||||
borderColor: AppColors.g3Border,
|
||||
items: _importantNotUrgent,
|
||||
onComplete: _completeTodo,
|
||||
onTap: _navigateToDetail,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -127,8 +226,9 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
required Color textColor,
|
||||
required Color dividerColor,
|
||||
required Color borderColor,
|
||||
required List<_TodoItem> items,
|
||||
required void Function(String) onRemove,
|
||||
required List<TodoResponse> items,
|
||||
required Future<void> Function(TodoResponse) onComplete,
|
||||
required void Function(TodoResponse) onTap,
|
||||
}) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
@@ -167,20 +267,33 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
const SizedBox(height: 8),
|
||||
Container(height: 1, color: dividerColor),
|
||||
const SizedBox(height: 8),
|
||||
...items.map((item) => _buildTodoItem(item, onRemove)),
|
||||
if (items.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'暂无待办',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 13,
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
...items.map(
|
||||
(item) => _TodoItemWidget(
|
||||
item: item,
|
||||
onComplete: () => onComplete(item),
|
||||
onTap: () => onTap(item),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTodoItem(_TodoItem item, void Function(String) onRemove) {
|
||||
return _TodoItemWidget(
|
||||
key: ValueKey(item.id),
|
||||
item: item,
|
||||
onRemove: onRemove,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomDock() {
|
||||
return BottomDock(
|
||||
activeTab: DockTab.todo,
|
||||
@@ -202,22 +315,15 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
class _TodoItem {
|
||||
final String id;
|
||||
final String title;
|
||||
|
||||
_TodoItem({required this.title})
|
||||
: id = DateTime.now().microsecondsSinceEpoch.toString();
|
||||
}
|
||||
|
||||
class _TodoItemWidget extends StatefulWidget {
|
||||
final _TodoItem item;
|
||||
final void Function(String) onRemove;
|
||||
final TodoResponse item;
|
||||
final VoidCallback onComplete;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _TodoItemWidget({
|
||||
super.key,
|
||||
required this.item,
|
||||
required this.onRemove,
|
||||
required this.onComplete,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -249,70 +355,326 @@ class _TodoItemWidgetState extends State<_TodoItemWidget>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _handleTap() {
|
||||
void _handleCheckTap() async {
|
||||
if (_isChecked) return;
|
||||
|
||||
setState(() {
|
||||
_isChecked = true;
|
||||
});
|
||||
_controller.forward().then((_) {
|
||||
widget.onRemove(widget.item.id);
|
||||
widget.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 42,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.item.title,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
return GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
child: SizedBox(
|
||||
height: 42,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.item.title,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: _handleTap,
|
||||
child: AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
return Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: _isChecked ? AppColors.blue600 : Colors.white,
|
||||
border: Border.all(
|
||||
color: _isChecked
|
||||
? AppColors.blue600
|
||||
: AppColors.slate300,
|
||||
width: 1.5,
|
||||
GestureDetector(
|
||||
onTap: _handleCheckTap,
|
||||
child: AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
return Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: _isChecked ? AppColors.blue600 : Colors.white,
|
||||
border: Border.all(
|
||||
color: _isChecked
|
||||
? AppColors.blue600
|
||||
: AppColors.slate300,
|
||||
width: 1.5,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: _isChecked
|
||||
? Transform.scale(
|
||||
scale: _scaleAnimation.value,
|
||||
child: const Icon(
|
||||
Icons.check,
|
||||
size: 14,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AddTodoSheet extends StatefulWidget {
|
||||
const _AddTodoSheet();
|
||||
|
||||
@override
|
||||
State<_AddTodoSheet> createState() => _AddTodoSheetState();
|
||||
}
|
||||
|
||||
class _AddTodoSheetState extends State<_AddTodoSheet> {
|
||||
final _titleController = TextEditingController();
|
||||
final _descriptionController = TextEditingController();
|
||||
int _priority = 1;
|
||||
final Set<String> _selectedScheduleItems = {};
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_titleController.dispose();
|
||||
_descriptionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: MediaQuery.of(context).size.height * 0.85,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'添加待办',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
child: _isChecked
|
||||
? Transform.scale(
|
||||
scale: _scaleAnimation.value,
|
||||
child: const Icon(
|
||||
Icons.check,
|
||||
size: 14,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
controller: _titleController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '标题',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
autofocus: true,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _descriptionController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '描述(可选)',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
maxLines: 2,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'优先级',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
_PriorityChip(
|
||||
label: '重要紧急',
|
||||
selected: _priority == 1,
|
||||
color: AppColors.g1Border,
|
||||
onTap: () => setState(() => _priority = 1),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_PriorityChip(
|
||||
label: '紧急不重要',
|
||||
selected: _priority == 3,
|
||||
color: AppColors.g2Border,
|
||||
onTap: () => setState(() => _priority = 3),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_PriorityChip(
|
||||
label: '重要不紧急',
|
||||
selected: _priority == 2,
|
||||
color: AppColors.g3Border,
|
||||
onTap: () => setState(() => _priority = 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'关联日历事件',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
child: FutureBuilder(
|
||||
future: _loadScheduleItems(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Center(child: Text('加载失败: ${snapshot.error}'));
|
||||
}
|
||||
final items = snapshot.data ?? [];
|
||||
if (items.isEmpty) {
|
||||
return const Center(child: Text('暂无日历事件'));
|
||||
}
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
final isSelected = _selectedScheduleItems.contains(item.id);
|
||||
return CheckboxListTile(
|
||||
title: Text(item.title),
|
||||
subtitle: Text(_formatDate(item.startAt)),
|
||||
value: isSelected,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
if (value == true) {
|
||||
_selectedScheduleItems.add(item.id);
|
||||
} else {
|
||||
_selectedScheduleItems.remove(item.id);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: AppButton(
|
||||
text: '添加',
|
||||
onPressed: () {
|
||||
if (_titleController.text.trim().isEmpty) {
|
||||
Toast.show(context, '请输入标题', type: ToastType.warning);
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pop({
|
||||
'title': _titleController.text.trim(),
|
||||
'description': _descriptionController.text.trim().isEmpty
|
||||
? null
|
||||
: _descriptionController.text.trim(),
|
||||
'priority': _priority,
|
||||
'schedule_item_ids': _selectedScheduleItems.toList(),
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<_ScheduleItemSimple>> _loadScheduleItems() async {
|
||||
final calendarApi = sl<CalendarApi>();
|
||||
final now = DateTime.now();
|
||||
final start = now.subtract(const Duration(days: 30));
|
||||
final end = now.add(const Duration(days: 90));
|
||||
final items = await calendarApi.listByRange(startAt: start, endAt: end);
|
||||
return items
|
||||
.map(
|
||||
(e) =>
|
||||
_ScheduleItemSimple(id: e.id, title: e.title, startAt: e.startAt),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
String _formatDate(DateTime dt) {
|
||||
return '${dt.year}年${dt.month}月${dt.day}日 ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
|
||||
class _ScheduleItemSimple {
|
||||
final String id;
|
||||
final String title;
|
||||
final DateTime startAt;
|
||||
|
||||
_ScheduleItemSimple({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.startAt,
|
||||
});
|
||||
}
|
||||
|
||||
class _PriorityChip extends StatelessWidget {
|
||||
final String label;
|
||||
final bool selected;
|
||||
final Color color;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _PriorityChip({
|
||||
required this.label,
|
||||
required this.selected,
|
||||
required this.color,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? color.withValues(alpha: 0.2) : Colors.transparent,
|
||||
border: Border.all(
|
||||
color: selected ? color : AppColors.slate300,
|
||||
width: selected ? 2 : 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 12,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.normal,
|
||||
color: selected ? color : AppColors.slate600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ void main() {
|
||||
final created = await api.create(
|
||||
ScheduleItemModel(
|
||||
id: 'evt_local',
|
||||
ownerId: 'user-1',
|
||||
title: '评审',
|
||||
startAt: DateTime.utc(2026, 3, 11, 3),
|
||||
endAt: DateTime.utc(2026, 3, 11, 4),
|
||||
@@ -118,6 +119,7 @@ void main() {
|
||||
final api = CalendarApi(client);
|
||||
final event = ScheduleItemModel(
|
||||
id: 'evt_3',
|
||||
ownerId: 'user-1',
|
||||
title: '同步会',
|
||||
startAt: DateTime.utc(2026, 3, 11, 1),
|
||||
metadata: ScheduleMetadata.fromJson({
|
||||
|
||||
@@ -29,6 +29,7 @@ void main() {
|
||||
_FakeCalendarService(
|
||||
event: ScheduleItemModel(
|
||||
id: 'evt_1',
|
||||
ownerId: 'user-1',
|
||||
title: '评审会',
|
||||
startAt: DateTime(2026, 3, 11, 15, 0),
|
||||
endAt: DateTime(2026, 3, 11, 16, 0),
|
||||
@@ -57,6 +58,7 @@ void main() {
|
||||
_FakeCalendarService(
|
||||
event: ScheduleItemModel(
|
||||
id: 'evt_2',
|
||||
ownerId: 'user-1',
|
||||
title: '同步会',
|
||||
startAt: DateTime(2026, 3, 12, 10, 0),
|
||||
metadata: ScheduleMetadata(version: 1),
|
||||
|
||||
@@ -102,7 +102,7 @@ void main() {
|
||||
|
||||
expect(fakeRecorder.started, true);
|
||||
expect(find.text('正在聆听...'), findsOneWidget);
|
||||
expect(_inputActionIcon(tester), LucideIcons.square);
|
||||
expect(_inputActionIcon(tester), LucideIcons.send);
|
||||
});
|
||||
|
||||
testWidgets('tap send while recording transcribes and auto sends message', (
|
||||
|
||||
Reference in New Issue
Block a user