feat:增加代办事项状态管理
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'layout/main_screen.dart';
|
import 'layout/main_screen.dart';
|
||||||
|
import 'store/todo_dialog_store.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@@ -13,8 +14,11 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChangeNotifierProvider(
|
return MultiProvider(
|
||||||
create: (context) => AppProvider(),
|
providers: [
|
||||||
|
ChangeNotifierProvider(create: (_) => AppProvider()),
|
||||||
|
ChangeNotifierProvider(create: (_) => TodoDialogStore()), // 新增
|
||||||
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
title: '闪灵',
|
title: '闪灵',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
import 'package:flisp_app/store/todo_dialog_store.dart';
|
||||||
|
import 'package:flisp_app/widgets/todo_widget.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:awesome_dialog/awesome_dialog.dart';
|
import 'package:awesome_dialog/awesome_dialog.dart';
|
||||||
import 'package:flisp_app/models/todo.dart';
|
import 'package:flisp_app/models/todo.dart';
|
||||||
import 'package:flisp_app/utils/todo_utils.dart';
|
import 'package:flisp_app/utils/todo_utils.dart';
|
||||||
import 'package:flisp_app/widgets/common.dart';
|
import 'package:flisp_app/widgets/common.dart';
|
||||||
import 'package:flisp_app/widgets/todo_dialog.dart';
|
import 'package:flisp_app/widgets/todo_dialog.dart';
|
||||||
import 'package:flisp_app/widgets/todo_widget.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class TodoPage extends StatefulWidget {
|
class TodoPage extends StatefulWidget {
|
||||||
final VoidCallback? onAddTodoPressed;
|
final VoidCallback? onAddTodoPressed;
|
||||||
@@ -16,28 +18,21 @@ class TodoPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TodoPageState extends State<TodoPage> {
|
class TodoPageState extends State<TodoPage> {
|
||||||
// 添加一个公共方法供外部调用
|
|
||||||
void showAddTodoDialog() {
|
|
||||||
_showAddTodoDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 待办事项列表
|
// 待办事项列表
|
||||||
final List<TodoItem> _todos = [
|
final List<TodoItem> _todos = [];
|
||||||
// ... 原有的待办事项数据保持不变
|
|
||||||
];
|
|
||||||
|
|
||||||
TodoTab _currentTab = TodoTab.all;
|
TodoTab _currentTab = TodoTab.all;
|
||||||
final TextEditingController _titleController = TextEditingController();
|
|
||||||
final TextEditingController _descriptionController = TextEditingController();
|
|
||||||
DateTime? _selectedDueDate;
|
|
||||||
TodoPriority _selectedPriority = TodoPriority.medium;
|
|
||||||
String? _selectedCategory;
|
|
||||||
|
|
||||||
// 获取过滤后的待办事项
|
// 获取过滤后的待办事项
|
||||||
List<TodoItem> get _activeTodos {
|
List<TodoItem> get _activeTodos {
|
||||||
return getActiveTodos(_currentTab, _todos);
|
return getActiveTodos(_currentTab, _todos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加一个公共方法供外部调用
|
||||||
|
void showAddTodoDialog() {
|
||||||
|
_showAddTodoDialog();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return buildBody(
|
return buildBody(
|
||||||
@@ -79,144 +74,64 @@ class TodoPageState extends State<TodoPage> {
|
|||||||
|
|
||||||
// 显示添加待办事项对话框
|
// 显示添加待办事项对话框
|
||||||
void _showAddTodoDialog() {
|
void _showAddTodoDialog() {
|
||||||
_resetForm();
|
final store = Provider.of<TodoDialogStore>(context, listen: false);
|
||||||
|
store.reset();
|
||||||
|
|
||||||
showAwesomeDialog(
|
showAwesomeDialog(
|
||||||
context: context,
|
context: context,
|
||||||
body: _buildTodoDialogContent(isEditing: false),
|
body: TodoDialog(isEditing: false),
|
||||||
onOk: () => _saveTodo(false, null),
|
onOk: () {
|
||||||
onCancel: () => _resetForm(),
|
if (store.validate()) {
|
||||||
|
_saveTodo(false, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCancel: () {
|
||||||
|
store.reset();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示编辑待办事项对话框
|
// 显示编辑待办事项对话框
|
||||||
void _showEditTodoDialog(TodoItem todo) {
|
void _showEditTodoDialog(TodoItem todo) {
|
||||||
_titleController.text = todo.title;
|
final store = Provider.of<TodoDialogStore>(context, listen: false);
|
||||||
_descriptionController.text = todo.description ?? '';
|
store.initEditData(todo);
|
||||||
_selectedDueDate = todo.dueDate;
|
|
||||||
_selectedPriority = todo.priority;
|
|
||||||
_selectedCategory = todo.category;
|
|
||||||
|
|
||||||
showAwesomeDialog(
|
showAwesomeDialog(
|
||||||
context: context,
|
context: context,
|
||||||
body: _buildTodoDialogContent(isEditing: true),
|
body: TodoDialog(isEditing: true, initialTodo: todo),
|
||||||
onOk: () => _saveTodo(true, todo),
|
onOk: () {
|
||||||
onCancel: () => _resetForm(),
|
if (store.validate()) {
|
||||||
|
_saveTodo(true, todo);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCancel: () {
|
||||||
|
store.reset();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建待办事项对话框 - 现在使用新的组件
|
|
||||||
Widget _buildTodoDialogContent({bool isEditing = false}) {
|
|
||||||
return TodoDialogContent(
|
|
||||||
isEditing: isEditing,
|
|
||||||
titleController: _titleController,
|
|
||||||
descriptionController: _descriptionController,
|
|
||||||
selectedDueDate: _selectedDueDate,
|
|
||||||
selectedPriority: _selectedPriority,
|
|
||||||
selectedCategory: _selectedCategory,
|
|
||||||
onDueDateChanged: (date) {
|
|
||||||
setState(() {
|
|
||||||
_selectedDueDate = date;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onPriorityChanged: (priority) {
|
|
||||||
setState(() {
|
|
||||||
_selectedPriority = priority;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onCategoryChanged: (category) {
|
|
||||||
setState(() {
|
|
||||||
_selectedCategory = category;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onClearDueDate: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedDueDate = null;
|
|
||||||
});
|
|
||||||
// 重新显示对话框以更新状态
|
|
||||||
if (isEditing) {
|
|
||||||
_showEditTodoDialog(_todos.firstWhere((todo) =>
|
|
||||||
_titleController.text == todo.title &&
|
|
||||||
_descriptionController.text == (todo.description ?? '')));
|
|
||||||
} else {
|
|
||||||
_showAddTodoDialog();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onSelectDueDate: () => _selectDueDateInDialog(isEditing),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在对话框中选择日期
|
|
||||||
Future<void> _selectDueDateInDialog(bool isEditing) async {
|
|
||||||
final DateTime? picked = await showDatePicker(
|
|
||||||
context: context,
|
|
||||||
initialDate: DateTime.now(),
|
|
||||||
firstDate: DateTime.now(),
|
|
||||||
lastDate: DateTime(2100),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (picked != null) {
|
|
||||||
setState(() {
|
|
||||||
_selectedDueDate = picked;
|
|
||||||
});
|
|
||||||
// 重新显示对话框以更新日期显示
|
|
||||||
if (isEditing) {
|
|
||||||
// 找到对应的待办事项重新显示编辑对话框
|
|
||||||
final todo = _todos.firstWhere((todo) =>
|
|
||||||
_titleController.text == todo.title &&
|
|
||||||
_descriptionController.text == (todo.description ?? ''));
|
|
||||||
_showEditTodoDialog(todo);
|
|
||||||
} else {
|
|
||||||
_showAddTodoDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证表单
|
|
||||||
bool _validateForm() {
|
|
||||||
return _titleController.text.trim().isNotEmpty;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重置表单
|
|
||||||
void _resetForm() {
|
|
||||||
_titleController.clear();
|
|
||||||
_descriptionController.clear();
|
|
||||||
_selectedDueDate = null;
|
|
||||||
_selectedPriority = TodoPriority.medium;
|
|
||||||
_selectedCategory = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存待办事项
|
// 保存待办事项
|
||||||
void _saveTodo(bool isEditing, TodoItem? todo) {
|
void _saveTodo(bool isEditing, TodoItem? todo) {
|
||||||
if (!_validateForm()) return;
|
final store = Provider.of<TodoDialogStore>(context, listen: false);
|
||||||
|
|
||||||
final newTodo = TodoItem(
|
final newTodo = store.createTodoItem(
|
||||||
id: isEditing ? todo!.id : DateTime.now().millisecondsSinceEpoch.toString(),
|
id: isEditing ? todo!.id : null,
|
||||||
title: _titleController.text.trim(),
|
isCompleted: isEditing ? todo!.isCompleted : false,
|
||||||
description: _descriptionController.text.trim().isEmpty
|
createdAt: isEditing ? todo!.createdAt : null,
|
||||||
? null
|
|
||||||
: _descriptionController.text.trim(),
|
|
||||||
dueDate: _selectedDueDate,
|
|
||||||
priority: _selectedPriority,
|
|
||||||
category: _selectedCategory,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
final index = _todos.indexWhere((t) => t.id == todo!.id);
|
final index = _todos.indexWhere((t) => t.id == todo!.id);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
_todos[index] = newTodo.copyWith(
|
_todos[index] = newTodo;
|
||||||
isCompleted: _todos[index].isCompleted,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_todos.insert(0, newTodo);
|
_todos.insert(0, newTodo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_resetForm();
|
store.reset();
|
||||||
|
|
||||||
// 显示成功提示
|
|
||||||
_showSuccessDialog(isEditing ? '更新成功' : '添加成功');
|
_showSuccessDialog(isEditing ? '更新成功' : '添加成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,11 +160,4 @@ class TodoPageState extends State<TodoPage> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_titleController.dispose();
|
|
||||||
_descriptionController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flisp_app/models/todo.dart';
|
||||||
|
|
||||||
|
class TodoDialogStore extends ChangeNotifier {
|
||||||
|
String _title = '';
|
||||||
|
String _description = '';
|
||||||
|
DateTime? _dueDate;
|
||||||
|
TodoPriority _priority = TodoPriority.medium;
|
||||||
|
String? _category;
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
String get title => _title;
|
||||||
|
String get description => _description;
|
||||||
|
DateTime? get dueDate => _dueDate;
|
||||||
|
TodoPriority get priority => _priority;
|
||||||
|
String? get category => _category;
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
set title(String value) {
|
||||||
|
_title = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
set description(String value) {
|
||||||
|
_description = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
set dueDate(DateTime? value) {
|
||||||
|
_dueDate = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
set priority(TodoPriority value) {
|
||||||
|
_priority = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
set category(String? value) {
|
||||||
|
_category = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化编辑数据
|
||||||
|
void initEditData(TodoItem todo) {
|
||||||
|
_title = todo.title;
|
||||||
|
_description = todo.description ?? '';
|
||||||
|
_dueDate = todo.dueDate;
|
||||||
|
_priority = todo.priority;
|
||||||
|
_category = todo.category;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置表单数据
|
||||||
|
void reset() {
|
||||||
|
_title = '';
|
||||||
|
_description = '';
|
||||||
|
_dueDate = null;
|
||||||
|
_priority = TodoPriority.medium;
|
||||||
|
_category = null;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证表单
|
||||||
|
bool validate() {
|
||||||
|
return _title.trim().isNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建待办事项对象
|
||||||
|
TodoItem createTodoItem({String? id, bool isCompleted = false, DateTime? createdAt}) {
|
||||||
|
return TodoItem(
|
||||||
|
id: id ?? DateTime.now().millisecondsSinceEpoch.toString(),
|
||||||
|
title: _title.trim(),
|
||||||
|
description: _description.trim().isEmpty ? null : _description.trim(),
|
||||||
|
dueDate: _dueDate,
|
||||||
|
priority: _priority,
|
||||||
|
category: _category,
|
||||||
|
isCompleted: isCompleted,
|
||||||
|
createdAt: createdAt ?? DateTime.now(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,43 +1,80 @@
|
|||||||
|
import 'package:flisp_app/store/todo_dialog_store.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flisp_app/models/todo.dart';
|
import 'package:flisp_app/models/todo.dart';
|
||||||
import 'package:flisp_app/utils/date_utils.dart';
|
import 'package:flisp_app/utils/date_utils.dart';
|
||||||
import 'package:flisp_app/widgets/common.dart';
|
import 'package:flisp_app/widgets/common.dart';
|
||||||
|
|
||||||
class TodoDialogContent extends StatefulWidget {
|
class TodoDialog extends StatefulWidget {
|
||||||
final bool isEditing;
|
final bool isEditing;
|
||||||
final TextEditingController titleController;
|
final TodoItem? initialTodo;
|
||||||
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({
|
const TodoDialog({
|
||||||
super.key,
|
super.key,
|
||||||
required this.isEditing,
|
required this.isEditing,
|
||||||
required this.titleController,
|
this.initialTodo,
|
||||||
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
|
@override
|
||||||
State<TodoDialogContent> createState() => _TodoDialogContentState();
|
State<TodoDialog> createState() => _TodoDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TodoDialogState extends State<TodoDialog> {
|
||||||
|
late TextEditingController _titleController;
|
||||||
|
late TextEditingController _descriptionController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_titleController = TextEditingController();
|
||||||
|
_descriptionController = TextEditingController();
|
||||||
|
|
||||||
|
// 如果是编辑模式,初始化数据
|
||||||
|
if (widget.isEditing && widget.initialTodo != null) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
final store = Provider.of<TodoDialogStore>(context, listen: false);
|
||||||
|
store.initEditData(widget.initialTodo!);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_titleController.dispose();
|
||||||
|
_descriptionController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _selectDueDate(BuildContext context) async {
|
||||||
|
final DateTime? picked = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: DateTime.now(),
|
||||||
|
firstDate: DateTime.now(),
|
||||||
|
lastDate: DateTime(2100),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (picked != null) {
|
||||||
|
final store = Provider.of<TodoDialogStore>(context, listen: false);
|
||||||
|
store.dueDate = picked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TodoDialogContentState extends State<TodoDialogContent> {
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final store = Provider.of<TodoDialogStore>(context);
|
||||||
|
|
||||||
|
// 同步控制器文本
|
||||||
|
if (_titleController.text != store.title) {
|
||||||
|
_titleController.text = store.title;
|
||||||
|
_titleController.selection = TextSelection.collapsed(offset: store.title.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_descriptionController.text != store.description) {
|
||||||
|
_descriptionController.text = store.description;
|
||||||
|
_descriptionController.selection = TextSelection.collapsed(offset: store.description.length);
|
||||||
|
}
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -62,16 +99,15 @@ class _TodoDialogContentState extends State<TodoDialogContent> {
|
|||||||
|
|
||||||
// 标题输入框
|
// 标题输入框
|
||||||
TextField(
|
TextField(
|
||||||
controller: widget.titleController,
|
controller: _titleController,
|
||||||
|
onChanged: (value) => store.title = value,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: '标题',
|
labelText: '标题',
|
||||||
hintText: '请输入待办事项标题...',
|
hintText: '请输入待办事项标题...',
|
||||||
counterText: '',
|
counterText: '',
|
||||||
suffixText: '${widget.titleController.text.length}/20',
|
suffixText: '${store.title.length}/20',
|
||||||
suffixStyle: TextStyle(
|
suffixStyle: TextStyle(
|
||||||
color: widget.titleController.text.length > 20
|
color: store.title.length > 20 ? Colors.red : Colors.grey,
|
||||||
? Colors.red
|
|
||||||
: Colors.grey,
|
|
||||||
),
|
),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -88,32 +124,25 @@ class _TodoDialogContentState extends State<TodoDialogContent> {
|
|||||||
filled: true,
|
filled: true,
|
||||||
fillColor: Colors.white,
|
fillColor: Colors.white,
|
||||||
prefixIcon: Icon(Icons.title, color: Colors.black87),
|
prefixIcon: Icon(Icons.title, color: Colors.black87),
|
||||||
contentPadding: EdgeInsets.symmetric(
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
horizontal: 16,
|
|
||||||
vertical: 14,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
style: TextStyle(fontSize: 16),
|
style: TextStyle(fontSize: 16),
|
||||||
maxLength: 20,
|
maxLength: 20,
|
||||||
onChanged: (value) {
|
|
||||||
if (mounted) setState(() {});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
|
|
||||||
// 描述输入框
|
// 描述输入框
|
||||||
TextField(
|
TextField(
|
||||||
controller: widget.descriptionController,
|
controller: _descriptionController,
|
||||||
|
onChanged: (value) => store.description = value,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: '内容',
|
labelText: '内容',
|
||||||
hintText: '请输入待办事项内容...',
|
hintText: '请输入待办事项内容...',
|
||||||
counterText: '',
|
counterText: '',
|
||||||
suffixText: '${widget.titleController.text.length}/50',
|
suffixText: '${store.description.length}/50',
|
||||||
suffixStyle: TextStyle(
|
suffixStyle: TextStyle(
|
||||||
color: widget.titleController.text.length > 20
|
color: store.description.length > 50 ? Colors.red : Colors.grey,
|
||||||
? Colors.red
|
|
||||||
: Colors.grey,
|
|
||||||
),
|
),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -130,10 +159,7 @@ class _TodoDialogContentState extends State<TodoDialogContent> {
|
|||||||
filled: true,
|
filled: true,
|
||||||
fillColor: Colors.white,
|
fillColor: Colors.white,
|
||||||
prefixIcon: Icon(Icons.description, color: Colors.black87),
|
prefixIcon: Icon(Icons.description, color: Colors.black87),
|
||||||
contentPadding: EdgeInsets.symmetric(
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
horizontal: 16,
|
|
||||||
vertical: 14,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
style: TextStyle(fontSize: 16),
|
style: TextStyle(fontSize: 16),
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
@@ -148,22 +174,22 @@ class _TodoDialogContentState extends State<TodoDialogContent> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: Icon(Icons.calendar_today, color: Colors.blue),
|
leading: Icon(Icons.calendar_today, color: Colors.blue),
|
||||||
title: Text(
|
title: Text(
|
||||||
widget.selectedDueDate == null
|
store.dueDate == null
|
||||||
? '选择截止日期'
|
? '选择截止日期'
|
||||||
: '截止: ${formatDate(widget.selectedDueDate!)}',
|
: '截止: ${formatDate(store.dueDate!)}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: widget.selectedDueDate == null
|
color: store.dueDate == null ? Colors.grey : Colors.black87,
|
||||||
? Colors.grey
|
|
||||||
: Colors.black87,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
trailing: widget.selectedDueDate != null
|
trailing: store.dueDate != null
|
||||||
? IconButton(
|
? IconButton(
|
||||||
icon: Icon(Icons.clear, size: 18),
|
icon: Icon(Icons.clear, size: 18),
|
||||||
onPressed: widget.onClearDueDate,
|
onPressed: () {
|
||||||
|
store.dueDate = null;
|
||||||
|
},
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
onTap: widget.onSelectDueDate,
|
onTap: () => _selectDueDate(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
@@ -175,12 +201,12 @@ class _TodoDialogContentState extends State<TodoDialogContent> {
|
|||||||
leading: Container(
|
leading: Container(
|
||||||
padding: EdgeInsets.all(6),
|
padding: EdgeInsets.all(6),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: widget.selectedPriority.color.withAlpha(10),
|
color: store.priority.color.withAlpha(10),
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.flag,
|
Icons.flag,
|
||||||
color: widget.selectedPriority.color,
|
color: store.priority.color,
|
||||||
size: 18,
|
size: 18,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -193,7 +219,7 @@ class _TodoDialogContentState extends State<TodoDialogContent> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
trailing: DropdownButton<TodoPriority>(
|
trailing: DropdownButton<TodoPriority>(
|
||||||
value: widget.selectedPriority,
|
value: store.priority,
|
||||||
underline: SizedBox(),
|
underline: SizedBox(),
|
||||||
icon: Icon(Icons.arrow_drop_down, color: Colors.grey.shade600),
|
icon: Icon(Icons.arrow_drop_down, color: Colors.grey.shade600),
|
||||||
iconSize: 20,
|
iconSize: 20,
|
||||||
@@ -201,8 +227,7 @@ class _TodoDialogContentState extends State<TodoDialogContent> {
|
|||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
widget.onPriorityChanged(value);
|
store.priority = value;
|
||||||
if (mounted) setState(() {});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
items: TodoPriority.values.map((priority) {
|
items: TodoPriority.values.map((priority) {
|
||||||
|
|||||||
Reference in New Issue
Block a user