feat:增加待办提醒功能
This commit is contained in:
@@ -79,6 +79,9 @@ Widget buildOmniDateButton({
|
||||
onPressed: () async {
|
||||
final DateTime? picked = await showOmniDateTimePicker(
|
||||
context: context,
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: 400,
|
||||
),
|
||||
initialDate: selectedDate ?? DateTime.now(),
|
||||
firstDate: DateTime(
|
||||
DateTime.now().year,
|
||||
|
||||
@@ -19,6 +19,7 @@ class _TaskDialogState extends State<TaskDialog> {
|
||||
late Priority _selectedPriority;
|
||||
DateTime? _selectedDueDate;
|
||||
DateTime? _selectedScheduleTime;
|
||||
DateTime? _createTime;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
@@ -29,6 +30,7 @@ class _TaskDialogState extends State<TaskDialog> {
|
||||
_selectedPriority = widget.task?.priority ?? Priority.medium;
|
||||
_selectedDueDate = widget.task?.dueDate;
|
||||
_selectedScheduleTime = widget.task?.scheduleTime;
|
||||
_createTime = widget.task?.createTime;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -38,8 +40,22 @@ class _TaskDialogState extends State<TaskDialog> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void onConfirmClick() {
|
||||
void onConfirmClick() async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
if (_selectedScheduleTime != null &&
|
||||
_selectedScheduleTime!.isBefore(DateTime.now())) {
|
||||
await displayInfoBar(
|
||||
context,
|
||||
builder: (context, close) {
|
||||
return InfoBar(
|
||||
title: const Text('提醒时间不能早于当前时间'),
|
||||
severity: InfoBarSeverity.error,
|
||||
);
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final task = Task(
|
||||
id: widget.task?.id,
|
||||
title: _titleController.text,
|
||||
@@ -48,6 +64,7 @@ class _TaskDialogState extends State<TaskDialog> {
|
||||
scheduleTime: _selectedScheduleTime,
|
||||
priority: _selectedPriority,
|
||||
isCompleted: widget.task?.isCompleted ?? false,
|
||||
createTime: _createTime,
|
||||
);
|
||||
widget.onSave(task);
|
||||
Navigator.pop(context);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:task_hub/models/task.dart';
|
||||
|
||||
class TaskItem extends StatelessWidget {
|
||||
@@ -39,11 +40,14 @@ class TaskItem extends StatelessWidget {
|
||||
Expanded(child: _buildTitle(context)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
if (task.desc != null && task.desc!.isNotEmpty) _buildDesc(),
|
||||
const SizedBox(height: 4),
|
||||
if (task.dueDate != null || task.scheduleTime != null)
|
||||
if (task.desc != null && task.desc!.isNotEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
_buildDesc(),
|
||||
],
|
||||
if (task.dueDate != null || task.scheduleTime != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
_buildDate(),
|
||||
]
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -92,7 +96,7 @@ class TaskItem extends StatelessWidget {
|
||||
Icon(FluentIcons.calendar, size: 12, color: Colors.grey),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'截止日期: ${_formatDate(task.dueDate!)}',
|
||||
'截止日期: ${DateFormat('yyyy-MM-dd').format(task.dueDate!)}',
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
@@ -101,7 +105,7 @@ class TaskItem extends StatelessWidget {
|
||||
Icon(FluentIcons.clock, size: 12, color: Colors.grey),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'提醒日期: ${_formatDate(task.scheduleTime!)}',
|
||||
'提醒日期: ${DateFormat('yyyy-MM-dd HH:mm:ss').format(task.scheduleTime!)}',
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
],
|
||||
@@ -181,8 +185,4 @@ class TaskItem extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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