b9e68e3bc8
Per-screen application of the design system to the Flutter app. Mirrors the web's surface phase landed in FabledScribe v26.04.28.1. Foundation port shipped in 0f05f47; this is the surface work. Lucide icon migration - Added lucide_icons ^0.257.0 dependency - 107 Material Icons references → LucideIcons across 21 files. Drop-in IconData swap (Icon(LucideIcons.X) instead of Icon(Icons.x)). - Lucide import added to each touched file. Input border radius - theme.dart inputDecorationTheme borderRadius 24 → 8 in both light and dark themes. Doc says radius-md (8px) for inputs; previous pill shape was Material default that the doc deviates from. Illuminated Transcript pattern (ChatMessageBubble) - User bubble: accent-tinted border → neutral Pewter (scheme.outline). Asymmetric corner already correct (bottomRight 4px). - Assistant bubble: topLeft corner 4 → 16; only bottomLeft stays 4 (the "tail" effect, mirroring web's `border-bottom-left-radius: 4px`). Background switched from surfaceContainerHighest (Slate) to surface (Iron) per the doc spec "card surface". - Assistant bubble glow shadow added — accent-tinted blur (28px alpha 0.14) + depth shadow (8px alpha 0.4 black). Mirrors web's --color-bubble-asst-shadow. ActionColors wiring (Hybrid rule) - 5 'Delete' confirm buttons across notes / tasks / chat conversations / calendar event sheet → Oxblood action-destructive via the ActionColors ThemeExtension defined in the foundation port. Foreground for ghost/text variants, backgroundColor for filled. - Calendar event Save button → Moss action-primary. The first call site to wire ActionColors.primary; serves as the pattern for future Save reclassifications. - Other Save buttons (note edit, task edit, project edit, etc.) still flow through colorScheme.primary (dusty violet) and read as brand-moment. Reclassifying those is deferred — the wiring pattern is established and can be applied incrementally as files are touched. Indigo cleanup - 4 hardcoded #7C3AED / #5B21B6 literals → dusty-violet equivalents (#5B4A8A / #3F3560). Spots: project_tasks_screen color fallback (×2), journal_screen gradient. Verification - flutter analyze: No issues found What's deferred - Per-screen Save / Cancel reclassification beyond the calendar event Save button. Wiring pattern established; rollout opportunistic. - Long-form 1.7 line-height on assistant Markdown content (would require MarkdownStyleSheet work; minor). - Surface walk on Knowledge / Projects / Settings screens for any hardcoded styling that needs touch. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
402 lines
14 KiB
Dart
402 lines
14 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:lucide_icons/lucide_icons.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../core/constants.dart';
|
|
import '../../core/exceptions.dart';
|
|
import '../../core/theme.dart';
|
|
import '../../data/models/task.dart';
|
|
import '../../providers/api_client_provider.dart';
|
|
import '../../providers/tasks_provider.dart';
|
|
import '../../widgets/project_selector.dart';
|
|
|
|
class TaskEditScreen extends ConsumerStatefulWidget {
|
|
final int? taskId;
|
|
final int? initialProjectId;
|
|
const TaskEditScreen({super.key, this.taskId, this.initialProjectId});
|
|
|
|
@override
|
|
ConsumerState<TaskEditScreen> createState() => _TaskEditScreenState();
|
|
}
|
|
|
|
class _TaskEditScreenState extends ConsumerState<TaskEditScreen> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
final _titleController = TextEditingController();
|
|
final _descController = TextEditingController();
|
|
TaskStatus _status = TaskStatus.todo;
|
|
TaskPriority _priority = TaskPriority.medium;
|
|
DateTime? _dueDate;
|
|
int? _projectId;
|
|
bool _saving = false;
|
|
List<Task> _subTasks = [];
|
|
|
|
late final Future<void> _initFuture;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_projectId = widget.initialProjectId;
|
|
_initFuture =
|
|
widget.taskId != null ? _loadExisting() : Future.value();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_titleController.dispose();
|
|
_descController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _loadExisting() async {
|
|
final repo = ref.read(tasksRepositoryProvider);
|
|
final task = await repo.getOne(widget.taskId!);
|
|
_titleController.text = task.title;
|
|
_descController.text = task.description ?? '';
|
|
_status = task.status;
|
|
_priority = task.priority;
|
|
_dueDate = task.dueDate;
|
|
_projectId = task.projectId;
|
|
// Fetch sub-tasks
|
|
final api = ref.read(tasksApiProvider);
|
|
final subs = await api.getSubTasks(widget.taskId!);
|
|
setState(() => _subTasks = subs);
|
|
}
|
|
|
|
Future<void> _save() async {
|
|
if (!_formKey.currentState!.validate()) return;
|
|
setState(() => _saving = true);
|
|
try {
|
|
if (widget.taskId == null) {
|
|
await ref.read(tasksProvider.notifier).create(
|
|
title: _titleController.text.trim(),
|
|
description: _descController.text.trim().isEmpty
|
|
? null
|
|
: _descController.text.trim(),
|
|
status: _status,
|
|
priority: _priority,
|
|
dueDate: _dueDate,
|
|
projectId: _projectId,
|
|
);
|
|
} else {
|
|
await ref.read(tasksProvider.notifier).updateTask(widget.taskId!, {
|
|
'title': _titleController.text.trim(),
|
|
'body': _descController.text.trim().isEmpty
|
|
? null
|
|
: _descController.text.trim(),
|
|
'status': _status.value,
|
|
'priority': _priority.value,
|
|
'due_date': _dueDate?.toIso8601String(),
|
|
'project_id': _projectId,
|
|
});
|
|
}
|
|
if (mounted) context.pop();
|
|
} on AppException catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(content: Text(e.message)));
|
|
}
|
|
} finally {
|
|
if (mounted) setState(() => _saving = false);
|
|
}
|
|
}
|
|
|
|
Future<void> _delete() async {
|
|
final confirm = await showDialog<bool>(
|
|
context: context,
|
|
builder: (dialogContext) => AlertDialog(
|
|
title: const Text('Delete task?'),
|
|
content: Text(_titleController.text),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext, false),
|
|
child: const Text('Cancel')),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext, true),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: Theme.of(dialogContext).extension<ActionColors>()!.destructive,
|
|
),
|
|
child: const Text('Delete')),
|
|
],
|
|
),
|
|
);
|
|
if (confirm == true) {
|
|
await ref.read(tasksProvider.notifier).delete(widget.taskId!);
|
|
if (mounted) context.pop();
|
|
}
|
|
}
|
|
|
|
Future<void> _pickDate() async {
|
|
final date = await showDatePicker(
|
|
context: context,
|
|
initialDate: _dueDate ?? DateTime.now(),
|
|
firstDate: DateTime(2020),
|
|
lastDate: DateTime(2100),
|
|
);
|
|
if (date != null) setState(() => _dueDate = date);
|
|
}
|
|
|
|
Future<void> _addSubTask() async {
|
|
final titleCtrl = TextEditingController();
|
|
final result = await showDialog<String>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('Add sub-task'),
|
|
content: TextField(
|
|
controller: titleCtrl,
|
|
autofocus: true,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Title',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
textInputAction: TextInputAction.done,
|
|
onSubmitted: (v) => Navigator.pop(ctx, v.trim()),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(ctx),
|
|
child: const Text('Cancel')),
|
|
FilledButton(
|
|
onPressed: () =>
|
|
Navigator.pop(ctx, titleCtrl.text.trim()),
|
|
child: const Text('Add')),
|
|
],
|
|
),
|
|
);
|
|
titleCtrl.dispose();
|
|
if (result == null || result.isEmpty || !mounted) return;
|
|
try {
|
|
final api = ref.read(tasksApiProvider);
|
|
final sub = await api.create(
|
|
title: result,
|
|
status: TaskStatus.todo,
|
|
priority: TaskPriority.none,
|
|
projectId: _projectId,
|
|
parentId: widget.taskId,
|
|
);
|
|
ref.invalidate(tasksProvider);
|
|
setState(() => _subTasks = [..._subTasks, sub]);
|
|
} on AppException catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(content: Text(e.message)));
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder(
|
|
future: _initFuture,
|
|
builder: (context, snapshot) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(widget.taskId == null ? 'New Task' : 'Edit Task'),
|
|
actions: [
|
|
if (widget.taskId != null)
|
|
IconButton(
|
|
icon: const Icon(LucideIcons.trash2),
|
|
onPressed: _delete,
|
|
),
|
|
IconButton(
|
|
icon: _saving
|
|
? const SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: const Icon(LucideIcons.check),
|
|
onPressed: _saving ? null : _save,
|
|
),
|
|
],
|
|
),
|
|
body: snapshot.connectionState == ConnectionState.waiting
|
|
? const Center(child: CircularProgressIndicator())
|
|
: Align(
|
|
alignment: Alignment.topCenter,
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 600),
|
|
child: Form(
|
|
key: _formKey,
|
|
child: ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
TextFormField(
|
|
controller: _titleController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Title',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
validator: (v) =>
|
|
(v == null || v.trim().isEmpty)
|
|
? 'Required'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: _descController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Description (optional)',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
maxLines: 3,
|
|
),
|
|
const SizedBox(height: 16),
|
|
DropdownButtonFormField<TaskStatus>(
|
|
// ignore: deprecated_member_use
|
|
value: _status,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Status',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
items: TaskStatus.values
|
|
.map((s) => DropdownMenuItem(
|
|
value: s, child: Text(s.label)))
|
|
.toList(),
|
|
onChanged: (v) =>
|
|
setState(() => _status = v!),
|
|
),
|
|
const SizedBox(height: 16),
|
|
DropdownButtonFormField<TaskPriority>(
|
|
// ignore: deprecated_member_use
|
|
value: _priority,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Priority',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
items: TaskPriority.values
|
|
.map((p) => DropdownMenuItem(
|
|
value: p, child: Text(p.label)))
|
|
.toList(),
|
|
onChanged: (v) =>
|
|
setState(() => _priority = v!),
|
|
),
|
|
const SizedBox(height: 16),
|
|
ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: Text(_dueDate == null
|
|
? 'No due date'
|
|
: 'Due: ${_dueDate!.toLocal().toString().substring(0, 10)}'),
|
|
leading: const Icon(LucideIcons.calendarDays),
|
|
trailing: _dueDate != null
|
|
? IconButton(
|
|
icon: const Icon(LucideIcons.x),
|
|
onPressed: () =>
|
|
setState(() => _dueDate = null),
|
|
)
|
|
: null,
|
|
onTap: _pickDate,
|
|
),
|
|
const SizedBox(height: 16),
|
|
ProjectSelector(
|
|
value: _projectId,
|
|
onChanged: (id) =>
|
|
setState(() => _projectId = id),
|
|
),
|
|
// Sub-tasks (only when editing an existing task)
|
|
if (widget.taskId != null) ...[
|
|
const SizedBox(height: 24),
|
|
_SubTasksSection(
|
|
subTasks: _subTasks,
|
|
onAdd: _addSubTask,
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
// ─── Sub-tasks section ─────────────────────────────────────────────────────────
|
|
|
|
class _SubTasksSection extends ConsumerWidget {
|
|
final List<Task> subTasks;
|
|
final VoidCallback onAdd;
|
|
const _SubTasksSection({required this.subTasks, required this.onAdd});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text(
|
|
'Sub-tasks',
|
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
TextButton.icon(
|
|
onPressed: onAdd,
|
|
icon: const Icon(LucideIcons.plus, size: 16),
|
|
label: const Text('Add'),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: colorScheme.primary,
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
textStyle: const TextStyle(fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (subTasks.isEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
child: Text(
|
|
'No sub-tasks yet.',
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: colorScheme.outline,
|
|
),
|
|
),
|
|
)
|
|
else
|
|
...subTasks.map((sub) => _SubTaskTile(task: sub, ref: ref)),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _SubTaskTile extends StatelessWidget {
|
|
final Task task;
|
|
final WidgetRef ref;
|
|
const _SubTaskTile({required this.task, required this.ref});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isDone = task.status == TaskStatus.done;
|
|
return ListTile(
|
|
dense: true,
|
|
contentPadding: EdgeInsets.zero,
|
|
leading: Checkbox(
|
|
value: isDone,
|
|
onChanged: (_) async {
|
|
final newStatus =
|
|
isDone ? TaskStatus.todo : TaskStatus.done;
|
|
await ref.read(tasksProvider.notifier).updateTask(
|
|
task.id, {'status': newStatus.value});
|
|
},
|
|
),
|
|
title: Text(
|
|
task.title,
|
|
style: TextStyle(
|
|
decoration: isDone ? TextDecoration.lineThrough : null,
|
|
color: isDone
|
|
? Theme.of(context).colorScheme.outline
|
|
: null,
|
|
),
|
|
),
|
|
onTap: () => context.push(
|
|
Routes.taskEdit.replaceFirst(':id', '${task.id}'),
|
|
),
|
|
);
|
|
}
|
|
}
|