feat:重构代办事项模块
This commit is contained in:
246
lib/widgets/todo_dialog.dart
Normal file
246
lib/widgets/todo_dialog.dart
Normal file
@@ -0,0 +1,246 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flisp_app/models/todo.dart';
|
||||
import 'package:flisp_app/utils/date_utils.dart';
|
||||
import 'package:flisp_app/widgets/common.dart';
|
||||
|
||||
class TodoDialogContent extends StatefulWidget {
|
||||
final bool isEditing;
|
||||
final TextEditingController titleController;
|
||||
final TextEditingController descriptionController;
|
||||
final DateTime? selectedDueDate;
|
||||
final TodoPriority selectedPriority;
|
||||
final String? selectedCategory;
|
||||
final Function(DateTime?) onDueDateChanged;
|
||||
final Function(TodoPriority) onPriorityChanged;
|
||||
final Function(String?) onCategoryChanged;
|
||||
final VoidCallback onClearDueDate;
|
||||
final VoidCallback onSelectDueDate;
|
||||
|
||||
const TodoDialogContent({
|
||||
super.key,
|
||||
required this.isEditing,
|
||||
required this.titleController,
|
||||
required this.descriptionController,
|
||||
required this.selectedDueDate,
|
||||
required this.selectedPriority,
|
||||
required this.selectedCategory,
|
||||
required this.onDueDateChanged,
|
||||
required this.onPriorityChanged,
|
||||
required this.onCategoryChanged,
|
||||
required this.onClearDueDate,
|
||||
required this.onSelectDueDate,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TodoDialogContent> createState() => _TodoDialogContentState();
|
||||
}
|
||||
|
||||
class _TodoDialogContentState extends State<TodoDialogContent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 标题
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.add_task, color: Colors.orange, size: 24),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
widget.isEditing ? '编辑待办事项' : '添加待办事项',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.orange,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
|
||||
// 标题输入框
|
||||
TextField(
|
||||
controller: widget.titleController,
|
||||
decoration: InputDecoration(
|
||||
labelText: '标题',
|
||||
hintText: '请输入待办事项标题...',
|
||||
counterText: '',
|
||||
suffixText: '${widget.titleController.text.length}/20',
|
||||
suffixStyle: TextStyle(
|
||||
color: widget.titleController.text.length > 20
|
||||
? Colors.red
|
||||
: Colors.grey,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.orange, width: 1),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
prefixIcon: Icon(Icons.title, color: Colors.black87),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 14,
|
||||
),
|
||||
),
|
||||
style: TextStyle(fontSize: 16),
|
||||
maxLength: 20,
|
||||
onChanged: (value) {
|
||||
if (mounted) setState(() {});
|
||||
},
|
||||
),
|
||||
|
||||
SizedBox(height: 12),
|
||||
|
||||
// 描述输入框
|
||||
TextField(
|
||||
controller: widget.descriptionController,
|
||||
decoration: InputDecoration(
|
||||
labelText: '内容',
|
||||
hintText: '请输入待办事项内容...',
|
||||
counterText: '',
|
||||
suffixText: '${widget.titleController.text.length}/50',
|
||||
suffixStyle: TextStyle(
|
||||
color: widget.titleController.text.length > 20
|
||||
? Colors.red
|
||||
: Colors.grey,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.orange, width: 1),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
prefixIcon: Icon(Icons.description, color: Colors.black87),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 14,
|
||||
),
|
||||
),
|
||||
style: TextStyle(fontSize: 16),
|
||||
maxLines: 2,
|
||||
maxLength: 50,
|
||||
),
|
||||
|
||||
SizedBox(height: 12),
|
||||
|
||||
// 截止日期选择
|
||||
Container(
|
||||
decoration: buildBoxDecoration(),
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.calendar_today, color: Colors.blue),
|
||||
title: Text(
|
||||
widget.selectedDueDate == null
|
||||
? '选择截止日期'
|
||||
: '截止: ${formatDate(widget.selectedDueDate!)}',
|
||||
style: TextStyle(
|
||||
color: widget.selectedDueDate == null
|
||||
? Colors.grey
|
||||
: Colors.black87,
|
||||
),
|
||||
),
|
||||
trailing: widget.selectedDueDate != null
|
||||
? IconButton(
|
||||
icon: Icon(Icons.clear, size: 18),
|
||||
onPressed: widget.onClearDueDate,
|
||||
)
|
||||
: null,
|
||||
onTap: widget.onSelectDueDate,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
|
||||
// 优先级选择
|
||||
Container(
|
||||
decoration: buildBoxDecoration(),
|
||||
child: ListTile(
|
||||
leading: Container(
|
||||
padding: EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: widget.selectedPriority.color.withAlpha(10),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.flag,
|
||||
color: widget.selectedPriority.color,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
'优先级',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey.shade700,
|
||||
),
|
||||
),
|
||||
trailing: DropdownButton<TodoPriority>(
|
||||
value: widget.selectedPriority,
|
||||
underline: SizedBox(),
|
||||
icon: Icon(Icons.arrow_drop_down, color: Colors.grey.shade600),
|
||||
iconSize: 20,
|
||||
dropdownColor: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
widget.onPriorityChanged(value);
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
},
|
||||
items: TodoPriority.values.map((priority) {
|
||||
return DropdownMenuItem(
|
||||
value: priority,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: buildBoxDecoration(),
|
||||
child: Icon(
|
||||
priority.icon,
|
||||
color: priority.color,
|
||||
size: 14,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Text(
|
||||
priority.label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16),
|
||||
minLeadingWidth: 0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user