feat:增加日程模块
This commit is contained in:
188
lib/widgets/task_item.dart
Normal file
188
lib/widgets/task_item.dart
Normal file
@@ -0,0 +1,188 @@
|
||||
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;
|
||||
|
||||
const TaskItem({
|
||||
super.key,
|
||||
required this.task,
|
||||
required this.onToggleComplete,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
@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: _buildTitle()),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
if (task.desc != null && task.desc!.isNotEmpty) _buildDesc(),
|
||||
const SizedBox(height: 2),
|
||||
if (task.dueDate != null || task.scheduleDate != null)
|
||||
_buildDate(),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(FluentIcons.edit, size: 16),
|
||||
onPressed: onEdit,
|
||||
),
|
||||
_buildDeleteButton(),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTitle() {
|
||||
return Text(
|
||||
task.title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
decoration: task.isCompleted ? TextDecoration.lineThrough : null,
|
||||
color: task.isCompleted ? Colors.grey : Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDesc() {
|
||||
return Text(
|
||||
task.desc!,
|
||||
style: TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 14,
|
||||
decoration: task.isCompleted ? TextDecoration.lineThrough : null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDate() {
|
||||
return Row(
|
||||
children: [
|
||||
if (task.dueDate != null) ...[
|
||||
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),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
if (task.scheduleDate != null) ...[
|
||||
const Icon(FluentIcons.clock, size: 12, color: Colors.grey),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'提醒日期: ${_formatDate(task.scheduleDate!)}',
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDeleteButton() {
|
||||
final controller = FlyoutController();
|
||||
|
||||
return FlyoutTarget(
|
||||
controller: controller,
|
||||
child: IconButton(
|
||||
icon: const Icon(FluentIcons.delete, size: 16),
|
||||
onPressed: () {
|
||||
controller.showFlyout<void>(
|
||||
builder: (context) {
|
||||
return FlyoutContent(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('确认删除该任务?'),
|
||||
const SizedBox(height: 12.0),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Button(
|
||||
onPressed: () {
|
||||
onDelete();
|
||||
Flyout.of(context).close();
|
||||
},
|
||||
child: const Text('确认'),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Button(
|
||||
onPressed: Flyout.of(context).close,
|
||||
child: const Text('取消'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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