feat:增加代办事项状态管理
This commit is contained in:
@@ -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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user