feat:初始化工程
This commit is contained in:
211
lib/widges/task_dialog.dart
Normal file
211
lib/widges/task_dialog.dart
Normal file
@@ -0,0 +1,211 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:task_hub/models/task.dart';
|
||||
|
||||
class TaskDialog extends StatefulWidget {
|
||||
final Task? task;
|
||||
final ValueChanged<Task> onSave;
|
||||
|
||||
const TaskDialog({super.key, this.task, required this.onSave});
|
||||
|
||||
@override
|
||||
State<TaskDialog> createState() => _TaskDialogState();
|
||||
}
|
||||
|
||||
class _TaskDialogState extends State<TaskDialog> {
|
||||
late TextEditingController _titleController;
|
||||
late TextEditingController _descriptionController;
|
||||
late Priority _selectedPriority;
|
||||
DateTime? _selectedDate;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_titleController = TextEditingController(text: widget.task?.title ?? '');
|
||||
_descriptionController = TextEditingController(
|
||||
text: widget.task?.description ?? '',
|
||||
);
|
||||
_selectedPriority = widget.task?.priority ?? Priority.medium;
|
||||
_selectedDate = widget.task?.dueDate;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_titleController.dispose();
|
||||
_descriptionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ContentDialog(
|
||||
title: Text(widget.task == null ? '添加任务' : '编辑任务'),
|
||||
content: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 标题
|
||||
_buildFormRow(
|
||||
label: '任务标题',
|
||||
required: true,
|
||||
child: TextFormBox(
|
||||
controller: _titleController,
|
||||
placeholder: '请输入任务标题',
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '任务标题不能为空';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 描述
|
||||
_buildFormRow(
|
||||
label: '任务描述',
|
||||
child: TextFormBox(
|
||||
controller: _descriptionController,
|
||||
placeholder: '请输入任务描述',
|
||||
maxLines: 3,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 优先级
|
||||
_buildFormRow(
|
||||
label: '优先级',
|
||||
child: RadioGroup<Priority>(
|
||||
groupValue: _selectedPriority,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
RadioButton<Priority>(
|
||||
value: Priority.low,
|
||||
content: Text('低'),
|
||||
),
|
||||
RadioButton<Priority>(
|
||||
value: Priority.medium,
|
||||
content: Text('中'),
|
||||
),
|
||||
RadioButton<Priority>(
|
||||
value: Priority.high,
|
||||
content: Text('高'),
|
||||
)
|
||||
],
|
||||
),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_selectedPriority = value;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 截止日期
|
||||
_buildFormRow(
|
||||
label: '截止日期',
|
||||
child: DatePicker(
|
||||
selected: _selectedDate,
|
||||
onChanged: (date) {
|
||||
setState(() {
|
||||
_selectedDate = date;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
Button(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
FilledButton(
|
||||
child: const Text('保存'),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
final task = Task(
|
||||
id: widget.task?.id,
|
||||
title: _titleController.text,
|
||||
description: _descriptionController.text.isEmpty
|
||||
? null
|
||||
: _descriptionController.text,
|
||||
dueDate: _selectedDate,
|
||||
priority: _selectedPriority,
|
||||
isCompleted: widget.task?.isCompleted ?? false,
|
||||
);
|
||||
widget.onSave(task);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 构建表单行
|
||||
Widget _buildFormRow({
|
||||
required String label,
|
||||
required Widget child,
|
||||
bool required = false,
|
||||
}) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 80,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (required)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(right: 4),
|
||||
child: Text(
|
||||
'*',
|
||||
style: TextStyle(color: Colors.red, fontSize: 16),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const Text(
|
||||
':',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 右侧表单控件
|
||||
Expanded(
|
||||
child: child,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _getPriorityLabel(Priority priority) {
|
||||
switch (priority) {
|
||||
case Priority.low:
|
||||
return '低';
|
||||
case Priority.medium:
|
||||
return '中';
|
||||
case Priority.high:
|
||||
return '高';
|
||||
}
|
||||
}
|
||||
}
|
||||
151
lib/widges/task_item.dart
Normal file
151
lib/widges/task_item.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:task_hub/models/task.dart';
|
||||
|
||||
class TaskItem extends StatelessWidget {
|
||||
final Task task;
|
||||
final VoidCallback onToggleComplete;
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onDelete;
|
||||
final ValueChanged<Priority> onPriorityChanged;
|
||||
|
||||
const TaskItem({
|
||||
super.key,
|
||||
required this.task,
|
||||
required this.onToggleComplete,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onPriorityChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Row(
|
||||
children: [
|
||||
// 完成状态复选框
|
||||
Checkbox(
|
||||
checked: task.isCompleted,
|
||||
onChanged: (value) => onToggleComplete(),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 任务信息
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
// 优先级指示器
|
||||
_buildPriorityIndicator(task.priority),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
decoration:
|
||||
task.isCompleted
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
color: task.isCompleted ? Colors.grey : Colors.red,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
if (task.description != null && task.description!.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
task.description!,
|
||||
style: TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 14,
|
||||
decoration:
|
||||
task.isCompleted
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
if (task.dueDate != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
FluentIcons.calendar,
|
||||
size: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'截止: ${_formatDate(task.dueDate!)}',
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// 操作按钮
|
||||
Row(
|
||||
children: [
|
||||
// 编辑按钮
|
||||
IconButton(
|
||||
icon: const Icon(FluentIcons.edit, size: 16),
|
||||
onPressed: onEdit,
|
||||
),
|
||||
// 删除按钮
|
||||
IconButton(
|
||||
icon: const Icon(FluentIcons.delete, size: 16),
|
||||
onPressed: onDelete,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPriorityIndicator(Priority priority) {
|
||||
final Map<Priority, (Color, String)> priorityInfo = {
|
||||
Priority.low: (Colors.grey, '低'),
|
||||
Priority.medium: (Colors.green, '中'),
|
||||
Priority.high: (Colors.red, '高'),
|
||||
};
|
||||
|
||||
final (color, label) = priorityInfo[priority]!;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user