feat:增加提醒事项

This commit is contained in:
2025-11-08 22:06:16 +08:00
parent 27f0638c01
commit d5ff4c9b02
30 changed files with 1490 additions and 199 deletions

View File

@@ -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),