feat:增加提醒事项
This commit is contained in:
208
lib/widgets/reminder_form.dart
Normal file
208
lib/widgets/reminder_form.dart
Normal file
@@ -0,0 +1,208 @@
|
||||
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()],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
96
lib/widgets/reminder_widget.dart
Normal file
96
lib/widgets/reminder_widget.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:flisp_app/provider/todo_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/models/todo.dart';
|
||||
import 'package:flisp_app/utils/date_utils.dart';
|
||||
|
||||
class TodoForm extends StatefulWidget {
|
||||
final GlobalKey<FormBuilderState> formKey;
|
||||
@@ -31,7 +31,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
Widget build(BuildContext context) {
|
||||
final int maxTitleCount = 10;
|
||||
final int maxContentCount = 20;
|
||||
final store = Provider.of<TodoProvider>(context);
|
||||
final provider = Provider.of<TodoProvider>(context);
|
||||
|
||||
Widget buildTitle() {
|
||||
return Row(
|
||||
@@ -57,17 +57,17 @@ class _TodoFormState extends State<TodoForm> {
|
||||
FormBuilderTextField buildTitleField() {
|
||||
return FormBuilderTextField(
|
||||
name: 'title',
|
||||
initialValue: store.formItem.title,
|
||||
initialValue: provider.formItem.title,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
store.formItem.title = value ?? '';
|
||||
provider.formItem.title = value ?? '';
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: '标题',
|
||||
hintText: '请输入待办事项标题...',
|
||||
counterText: '',
|
||||
suffixText: '${store.formItem.title.length}/$maxTitleCount',
|
||||
suffixText: '${provider.formItem.title.length}/$maxTitleCount',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||
@@ -98,20 +98,20 @@ class _TodoFormState extends State<TodoForm> {
|
||||
);
|
||||
}
|
||||
|
||||
FormBuilderTextField buildDescriptionField() {
|
||||
FormBuilderTextField buildContentField() {
|
||||
return FormBuilderTextField(
|
||||
name: 'description',
|
||||
initialValue: store.formItem.content,
|
||||
name: 'content',
|
||||
initialValue: provider.formItem.content,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
store.formItem.content = value ?? '';
|
||||
provider.formItem.content = value ?? '';
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: '内容',
|
||||
hintText: '请输入待办事项内容...',
|
||||
counterText: '',
|
||||
suffixText: '${store.formItem.content.length}/$maxContentCount',
|
||||
suffixText: '${provider.formItem.content.length}/$maxContentCount',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.grey.shade200),
|
||||
@@ -145,7 +145,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
icon: Icon(Icons.clear, size: 18),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
store.formItem.dueDate = null;
|
||||
provider.formItem.dueDate = null;
|
||||
});
|
||||
widget.formKey.currentState?.fields['dueDate']?.didChange(null);
|
||||
},
|
||||
@@ -155,21 +155,24 @@ class _TodoFormState extends State<TodoForm> {
|
||||
FormBuilderDateTimePicker buildDateField() {
|
||||
return FormBuilderDateTimePicker(
|
||||
name: 'dueDate',
|
||||
initialValue: store.formItem.dueDate,
|
||||
format: DateFormat('yyyy-MM-dd'),
|
||||
initialValue: provider.formItem.dueDate,
|
||||
inputType: InputType.date,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
store.formItem.dueDate = value;
|
||||
provider.formItem.dueDate = value;
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText:
|
||||
store.formItem.dueDate == null
|
||||
provider.formItem.dueDate == null
|
||||
? '选择截止日期'
|
||||
: '截止: ${formatDate(store.formItem.dueDate!)}',
|
||||
: '截止: ${DateFormat('yyyy-MM-dd').format(provider.formItem.dueDate!)}',
|
||||
labelStyle: TextStyle(
|
||||
color:
|
||||
store.formItem.dueDate == null ? Colors.grey : Colors.black87,
|
||||
provider.formItem.dueDate == null
|
||||
? Colors.grey
|
||||
: Colors.black87,
|
||||
),
|
||||
prefixIcon: Icon(Icons.calendar_today, color: Colors.purple),
|
||||
border: OutlineInputBorder(
|
||||
@@ -188,7 +191,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
fillColor: Colors.white,
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
suffixIcon:
|
||||
store.formItem.dueDate != null
|
||||
provider.formItem.dueDate != null
|
||||
? buildClearDateSuffixIcon()
|
||||
: null,
|
||||
),
|
||||
@@ -205,7 +208,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
FormBuilderRadioGroup builderRadioGroup() {
|
||||
return FormBuilderRadioGroup<TodoPriority>(
|
||||
name: 'priority',
|
||||
initialValue: store.formItem.priority,
|
||||
initialValue: provider.formItem.priority,
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -225,7 +228,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
store.formItem.priority = value;
|
||||
provider.formItem.priority = value;
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -264,7 +267,7 @@ class _TodoFormState extends State<TodoForm> {
|
||||
children: [
|
||||
buildTitleField(),
|
||||
SizedBox(height: 12),
|
||||
buildDescriptionField(),
|
||||
buildContentField(),
|
||||
SizedBox(height: 12),
|
||||
buildDateField(),
|
||||
SizedBox(height: 12),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flisp_app/models/todo.dart';
|
||||
import 'package:flisp_app/utils/date_utils.dart';
|
||||
import 'package:flisp_app/widgets/common.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:toggle_switch/toggle_switch.dart';
|
||||
|
||||
// 统计卡片
|
||||
@@ -119,6 +119,7 @@ Widget _buildTodoTitle(Todo todo) {
|
||||
style: TextStyle(
|
||||
decoration: todo.isCompleted ? TextDecoration.lineThrough : null,
|
||||
color: todo.isCompleted ? Colors.grey : null,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
);
|
||||
@@ -128,31 +129,45 @@ Widget _buildTodoTitle(Todo todo) {
|
||||
Widget? _buildTodoSubtitle(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;
|
||||
|
||||
if (!hasContent) return null;
|
||||
|
||||
return Wrap(
|
||||
direction: Axis.vertical,
|
||||
spacing: 5,
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: 4),
|
||||
if (todo.content.isNotEmpty == true)
|
||||
Text(
|
||||
todo.content,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey.shade600),
|
||||
),
|
||||
if (todo.dueDate != null)
|
||||
Text(
|
||||
'截止: ${formatDate(todo.dueDate!)}',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: isOverdue ? Colors.red : Colors.grey,
|
||||
fontWeight: isOverdue ? FontWeight.bold : FontWeight.normal,
|
||||
fontSize: 14,
|
||||
color: Colors.grey[700],
|
||||
),
|
||||
),
|
||||
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