feat:合并待办和提醒功能
This commit is contained in:
@@ -1,208 +0,0 @@
|
||||
import 'package:flisp_app/models/reminder.dart';
|
||||
import 'package:flisp_app/provider/reminder_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flisp_app/utils/date_utils.dart';
|
||||
|
||||
class ReminderForm extends StatefulWidget {
|
||||
final GlobalKey<FormBuilderState> formKey;
|
||||
final bool isEditing;
|
||||
final Reminder? initialReminder;
|
||||
|
||||
const ReminderForm({
|
||||
super.key,
|
||||
required this.formKey,
|
||||
required this.isEditing,
|
||||
this.initialReminder,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ReminderForm> createState() => _ReminderFormState();
|
||||
}
|
||||
|
||||
class _ReminderFormState extends State<ReminderForm> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final int maxTitleCount = 10;
|
||||
final int maxContentCount = 20;
|
||||
final provider = Provider.of<ReminderProvider>(context);
|
||||
|
||||
Widget buildTitle() {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
widget.isEditing ? Icons.edit_note : Icons.add_task,
|
||||
color: Colors.orange,
|
||||
size: 24,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
widget.isEditing ? '编辑提醒事项' : '添加提醒事项',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.orange,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
FormBuilderTextField buildTitleField() {
|
||||
return FormBuilderTextField(
|
||||
name: 'title',
|
||||
initialValue: provider.formItem.title,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
provider.formItem.title = value ?? '';
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: '标题',
|
||||
hintText: '请输入提醒事项标题...',
|
||||
counterText: '',
|
||||
suffixText: '${provider.formItem.title.length}/$maxTitleCount',
|
||||
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),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
prefixIcon: Icon(Icons.title, color: Colors.blue),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
),
|
||||
maxLength: maxTitleCount,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入标题';
|
||||
}
|
||||
if (value.length > maxTitleCount) {
|
||||
return '标题不能超过$maxTitleCount个字符';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
FormBuilderTextField buildContentField() {
|
||||
return FormBuilderTextField(
|
||||
name: 'content',
|
||||
initialValue: provider.formItem.content,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
provider.formItem.content = value ?? '';
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: '内容',
|
||||
hintText: '请输入提醒事项内容...',
|
||||
counterText: '',
|
||||
suffixText: '${provider.formItem.content.length}/$maxContentCount',
|
||||
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),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
prefixIcon: Icon(Icons.description, color: Colors.green),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
),
|
||||
maxLines: 2,
|
||||
maxLength: maxContentCount,
|
||||
validator: (value) {
|
||||
if (value != null && value.length > maxContentCount) {
|
||||
return '内容不能超过$maxContentCount个字符';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
FormBuilderDateTimePicker buildDateField() {
|
||||
return FormBuilderDateTimePicker(
|
||||
name: 'dueDate',
|
||||
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
||||
initialValue: provider.formItem.scheduledTime,
|
||||
inputType: InputType.both,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
provider.formItem.scheduledTime = value!;
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: '提醒时间',
|
||||
labelStyle: TextStyle(color: Colors.black87),
|
||||
prefixIcon: Icon(Icons.calendar_today, color: Colors.purple),
|
||||
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),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value != null && value.isBefore(DateTime.now())) {
|
||||
return '不能选择过去的时间';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
FormBuilder buildForm() {
|
||||
return FormBuilder(
|
||||
key: widget.formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
buildTitleField(),
|
||||
SizedBox(height: 12),
|
||||
buildContentField(),
|
||||
SizedBox(height: 12),
|
||||
buildDateField(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [buildTitle(), SizedBox(height: 20), buildForm()],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
import 'package:flisp_app/models/reminder.dart';
|
||||
import 'package:flisp_app/widgets/common.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
Widget buildReminderList({
|
||||
required List<Reminder> reminders,
|
||||
required ValueChanged<Reminder> onEditReminder,
|
||||
}) {
|
||||
return ListView.separated(
|
||||
itemCount: reminders.length,
|
||||
separatorBuilder: (context, index) => SizedBox(height: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final reminder = reminders[index];
|
||||
return _buildReminderItem(reminder: reminder, onEdit: onEditReminder);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReminderItem({
|
||||
required Reminder reminder,
|
||||
required ValueChanged<Reminder> onEdit,
|
||||
}) {
|
||||
return buildCard(
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 0),
|
||||
leading: Icon(Icons.notifications, color: Colors.blue),
|
||||
title: _buildReminderTitle(reminder),
|
||||
subtitle: _buildReminderSubtitle(reminder),
|
||||
onTap: () => onEdit(reminder),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReminderTitle(Reminder reminder) {
|
||||
return Text(
|
||||
reminder.title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReminderSubtitle(Reminder reminder) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
reminder.content,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[700],
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue[50],
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
DateFormat('MM月dd日 HH:mm').format(reminder.scheduledTime),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.blue[700],
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 空状态
|
||||
Widget buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.task_alt, size: 80, color: Colors.orange.shade600),
|
||||
Text(
|
||||
'📋 还没有任何待办事项\n点击下方+号开始规划你的任务吧!',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.orange.shade600),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
);
|
||||
}
|
||||
|
||||
IconButton buildClearDateSuffixIcon() {
|
||||
IconButton buildClearDueDateSuffixIcon() {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.clear, size: 18),
|
||||
onPressed: () {
|
||||
@@ -152,7 +152,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
);
|
||||
}
|
||||
|
||||
FormBuilderDateTimePicker buildDateField() {
|
||||
FormBuilderDateTimePicker buildDueDateField() {
|
||||
return FormBuilderDateTimePicker(
|
||||
name: 'dueDate',
|
||||
format: DateFormat('yyyy-MM-dd'),
|
||||
@@ -192,7 +192,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
suffixIcon:
|
||||
provider.formItem.dueDate != null
|
||||
? buildClearDateSuffixIcon()
|
||||
? buildClearDueDateSuffixIcon()
|
||||
: null,
|
||||
),
|
||||
validator: (value) {
|
||||
@@ -205,6 +205,70 @@ class _TodoFormState extends State<TodoForm> {
|
||||
);
|
||||
}
|
||||
|
||||
IconButton buildClearScheduledTimeSuffixIcon() {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.clear, size: 18),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
provider.formItem.scheduledTime = null;
|
||||
});
|
||||
widget.formKey.currentState?.fields['scheduledTime']?.didChange(null);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
FormBuilderDateTimePicker buildScheduledTimeField() {
|
||||
return FormBuilderDateTimePicker(
|
||||
name: 'scheduledTime',
|
||||
format: DateFormat('yyyy-MM-dd HH:mm:ss'),
|
||||
initialValue: provider.formItem.scheduledTime,
|
||||
inputType: InputType.both,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
provider.formItem.scheduledTime = value;
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText:
|
||||
provider.formItem.scheduledTime == null
|
||||
? '选择提醒日期'
|
||||
: '提醒: ${DateFormat('yyyy-MM-dd HH:mm:ss').format(provider.formItem.scheduledTime!)}',
|
||||
labelStyle: TextStyle(
|
||||
color:
|
||||
provider.formItem.scheduledTime == null
|
||||
? Colors.grey
|
||||
: Colors.black87,
|
||||
),
|
||||
prefixIcon: Icon(Icons.calendar_today, color: Colors.purple),
|
||||
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),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
suffixIcon:
|
||||
provider.formItem.scheduledTime != null
|
||||
? buildClearScheduledTimeSuffixIcon()
|
||||
: null,
|
||||
),
|
||||
validator: (value) {
|
||||
if (value != null && value.isBefore(DateTime.now())) {
|
||||
return '不能选择过去的日期';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
FormBuilderRadioGroup builderRadioGroup() {
|
||||
return FormBuilderRadioGroup<TodoPriority>(
|
||||
name: 'priority',
|
||||
@@ -269,7 +333,9 @@ class _TodoFormState extends State<TodoForm> {
|
||||
SizedBox(height: 12),
|
||||
buildContentField(),
|
||||
SizedBox(height: 12),
|
||||
buildDateField(),
|
||||
buildDueDateField(),
|
||||
SizedBox(height: 12),
|
||||
buildScheduledTimeField(),
|
||||
SizedBox(height: 12),
|
||||
buildPriorityField(),
|
||||
],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flisp_app/models/todo.dart';
|
||||
import 'package:flisp_app/utils/todo_utils.dart';
|
||||
import 'package:flisp_app/widgets/common.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -125,52 +126,128 @@ Widget _buildTodoTitle(Todo todo) {
|
||||
);
|
||||
}
|
||||
|
||||
// 构建待办事项副标题
|
||||
Widget? _buildTodoSubtitle(Todo todo) {
|
||||
Widget _buildContent(Todo todo) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
todo.content,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 13, color: Colors.grey[600], height: 1.3),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDueDateChip(Todo todo) {
|
||||
final isOverdue =
|
||||
todo.dueDate != null &&
|
||||
todo.dueDate!.isBefore(DateTime.now()) &&
|
||||
!todo.isCompleted;
|
||||
todo.dueDate!.isBefore(DateTime.now()) &&
|
||||
!todo.isCompleted;
|
||||
|
||||
final hasContent = todo.content.isNotEmpty == true || todo.dueDate != null;
|
||||
final isDueToday =
|
||||
todo.dueDate != null && isSameDay(todo.dueDate!, DateTime.now());
|
||||
|
||||
final isDueTomorrow =
|
||||
todo.dueDate != null &&
|
||||
isSameDay(todo.dueDate!, DateTime.now().add(Duration(days: 1)));
|
||||
|
||||
return _buildInfoChip(
|
||||
icon: Icons.access_time_rounded,
|
||||
text: formatDueDate(todo.dueDate!, isDueToday, isDueTomorrow),
|
||||
backgroundColor:
|
||||
isOverdue
|
||||
? Colors.red[50]!
|
||||
: (isDueToday ? Colors.orange[50]! : Colors.grey[50]!),
|
||||
borderColor:
|
||||
isOverdue
|
||||
? Colors.red[200]!
|
||||
: (isDueToday ? Colors.orange[200]! : Colors.grey[300]!),
|
||||
textColor:
|
||||
isOverdue
|
||||
? Colors.red[700]!
|
||||
: (isDueToday ? Colors.orange[700]! : Colors.grey[700]!),
|
||||
iconColor:
|
||||
isOverdue
|
||||
? Colors.red[500]!
|
||||
: (isDueToday ? Colors.orange[500]! : Colors.grey[500]!),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildScheduledTimeChip(Todo todo) {
|
||||
return _buildInfoChip(
|
||||
icon: Icons.notifications_active_rounded,
|
||||
text: DateFormat("MM-dd HH:mm").format(todo.scheduledTime!),
|
||||
backgroundColor: Colors.blue[50]!,
|
||||
borderColor: Colors.blue[200]!,
|
||||
textColor: Colors.blue[700]!,
|
||||
iconColor: Colors.blue[500]!,
|
||||
);
|
||||
}
|
||||
|
||||
// 构建待办事项副标题
|
||||
Widget? _buildTodoSubtitle(Todo todo) {
|
||||
final hasContent =
|
||||
todo.content.isNotEmpty == true ||
|
||||
todo.dueDate != null ||
|
||||
todo.scheduledTime != null;
|
||||
|
||||
if (!hasContent) return null;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: 4),
|
||||
if (todo.content.isNotEmpty == true)
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 内容文本
|
||||
if (todo.content.isNotEmpty == true) _buildContent(todo),
|
||||
// 标签容器
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: [
|
||||
// 截止日期标签
|
||||
if (todo.dueDate != null) _buildDueDateChip(todo),
|
||||
// 提醒时间标签
|
||||
if (todo.scheduledTime != null) _buildScheduledTimeChip(todo),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 构建信息标签
|
||||
Widget _buildInfoChip({
|
||||
required IconData icon,
|
||||
required String text,
|
||||
required Color backgroundColor,
|
||||
required Color borderColor,
|
||||
required Color textColor,
|
||||
required Color iconColor,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: borderColor, width: 1),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 12, color: iconColor),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
todo.content,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[700],
|
||||
fontSize: 10,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.2,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
if (todo.dueDate != null)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: isOverdue ? Colors.red[50] : Colors.grey[50],
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(
|
||||
color: isOverdue ? Colors.red[100]! : Colors.grey[300]!,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'截止: ${DateFormat("yyyy-MM-dd").format(todo.dueDate!)}',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: isOverdue ? Colors.red[600] : Colors.grey[600],
|
||||
fontWeight: isOverdue ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user