feat(apps/todo): 新增 TodoEditScreen 编辑功能
This commit is contained in:
@@ -2,16 +2,16 @@ 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/router/app_routes.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../../shared/widgets/app_loading_indicator.dart';
|
||||
import '../../../home/ui/navigation/home_return_policy.dart';
|
||||
import '../../../../shared/widgets/app_pull_refresh_feedback.dart';
|
||||
import '../../../../shared/widgets/app_pressable.dart';
|
||||
import '../../../../shared/widgets/app_sheet_input_field.dart';
|
||||
import '../../../../shared/widgets/back_title_page_header.dart';
|
||||
import '../../../../shared/widgets/error_retry_surface.dart';
|
||||
import '../../../../shared/widgets/full_screen_loading.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';
|
||||
@@ -115,31 +115,13 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
}
|
||||
|
||||
void _navigateToDetail(TodoResponse todo) {
|
||||
context.push('/todo/${todo.id}');
|
||||
context.push(AppRoutes.todoDetail(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);
|
||||
}
|
||||
}
|
||||
final created = await context.push<bool>(AppRoutes.todoCreate);
|
||||
if (created == true) {
|
||||
await _loadTodos();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +133,7 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) {
|
||||
context.go('/home');
|
||||
returnToHomePreserveState(context);
|
||||
}
|
||||
},
|
||||
child: SafeArea(
|
||||
@@ -225,20 +207,11 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
|
||||
Widget _buildContent() {
|
||||
if (_isLoading) {
|
||||
return const Center(child: AppLoadingIndicator(size: 22));
|
||||
return const FullScreenLoading();
|
||||
}
|
||||
|
||||
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 ErrorRetrySurface(message: '加载失败: $_error', onRetry: _loadTodos);
|
||||
}
|
||||
|
||||
return Stack(
|
||||
@@ -379,12 +352,12 @@ class _TodoQuadrantsScreenState extends State<TodoQuadrantsScreen> {
|
||||
final dateStr =
|
||||
'${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||
if (viewType == CalendarViewType.month) {
|
||||
context.go('/calendar/month');
|
||||
context.push(AppRoutes.calendarMonth);
|
||||
} else {
|
||||
context.go('/calendar/dayweek?date=$dateStr');
|
||||
context.push('${AppRoutes.calendarDayWeek}?date=$dateStr');
|
||||
}
|
||||
},
|
||||
onHomeTap: () => context.go('/home'),
|
||||
onHomeTap: () => returnToHomePreserveState(context),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -499,356 +472,3 @@ class _TodoItemWidgetState extends State<_TodoItemWidget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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 = {};
|
||||
late final Future<List<_ScheduleItemSimple>> _scheduleItemsFuture;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scheduleItemsFuture = _loadScheduleItems();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_titleController.dispose();
|
||||
_descriptionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
|
||||
|
||||
return AnimatedPadding(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
curve: Curves.easeOut,
|
||||
padding: EdgeInsets.only(bottom: bottomInset),
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).size.height * 0.85,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(AppRadius.xxl),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Center(
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate200,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: AppSpacing.xl),
|
||||
child: Text(
|
||||
'添加待办',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
keyboardDismissBehavior:
|
||||
ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xl),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInputField(
|
||||
controller: _titleController,
|
||||
label: '标题',
|
||||
hint: '输入待办标题',
|
||||
autofocus: true,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildInputField(
|
||||
controller: _descriptionController,
|
||||
label: '描述(可选)',
|
||||
hint: '补充细节或备注',
|
||||
maxLines: 2,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
const Text(
|
||||
'优先级',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
_PriorityChip(
|
||||
label: '重要紧急',
|
||||
selected: _priority == 1,
|
||||
color: AppColors.g1Border,
|
||||
onTap: () => setState(() => _priority = 1),
|
||||
),
|
||||
_PriorityChip(
|
||||
label: '紧急不重要',
|
||||
selected: _priority == 3,
|
||||
color: AppColors.g2Border,
|
||||
onTap: () => setState(() => _priority = 3),
|
||||
),
|
||||
_PriorityChip(
|
||||
label: '重要不紧急',
|
||||
selected: _priority == 2,
|
||||
color: AppColors.g3Border,
|
||||
onTap: () => setState(() => _priority = 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
const Text(
|
||||
'关联日历事件',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Container(
|
||||
constraints: const BoxConstraints(maxHeight: 260),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate50,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: FutureBuilder<List<_ScheduleItemSimple>>(
|
||||
future: _scheduleItemsFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState ==
|
||||
ConnectionState.waiting) {
|
||||
return _buildScheduleSkeleton();
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
child: Text(
|
||||
'加载失败: ${snapshot.error}',
|
||||
style: const TextStyle(color: AppColors.red500),
|
||||
),
|
||||
);
|
||||
}
|
||||
final items = snapshot.data ?? const [];
|
||||
if (items.isEmpty) {
|
||||
return const SizedBox(
|
||||
height: 120,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'暂无日历事件',
|
||||
style: TextStyle(color: AppColors.slate500),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.sm,
|
||||
vertical: AppSpacing.xs,
|
||||
),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
final isSelected = _selectedScheduleItems
|
||||
.contains(item.id);
|
||||
return CheckboxListTile(
|
||||
dense: true,
|
||||
value: isSelected,
|
||||
title: Text(item.title),
|
||||
subtitle: Text(_formatDate(item.startAt)),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
if (value == true) {
|
||||
_selectedScheduleItems.add(item.id);
|
||||
} else {
|
||||
_selectedScheduleItems.remove(item.id);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.lg,
|
||||
AppSpacing.sm,
|
||||
AppSpacing.lg,
|
||||
AppSpacing.lg,
|
||||
),
|
||||
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(),
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInputField({
|
||||
required TextEditingController controller,
|
||||
required String label,
|
||||
required String hint,
|
||||
int maxLines = 1,
|
||||
bool autofocus = false,
|
||||
}) {
|
||||
return AppSheetInputField(
|
||||
controller: controller,
|
||||
label: label,
|
||||
hint: hint,
|
||||
maxLines: maxLines,
|
||||
autofocus: autofocus,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildScheduleSkeleton() {
|
||||
return ListView.separated(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.md,
|
||||
),
|
||||
itemCount: 4,
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
itemBuilder: (context, index) {
|
||||
return Container(
|
||||
height: AppSpacing.xxl + AppSpacing.lg,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user