Flutter 使用可交互的listview项和提供程序模式持久化数据
这个问题可以用带有每个项目进度的待办事项列表来重新定义 我有一个目标列表,每个目标都有文本和进度Flutter 使用可交互的listview项和提供程序模式持久化数据,flutter,dart,Flutter,Dart,这个问题可以用带有每个项目进度的待办事项列表来重新定义 我有一个目标列表,每个目标都有文本和进度 class Goal { int progress; String goalText; } 为了显示它们,它们被包装在ChangeNotifier状态对象中 class GoalListState with ChangeNotifier { List<Goal> goals; } 然后我在ListView中使用它,ListView中的每个项目都有一个进度滑块来
class Goal {
int progress;
String goalText;
}
为了显示它们,它们被包装在ChangeNotifier状态对象中
class GoalListState with ChangeNotifier {
List<Goal> goals;
}
然后我在ListView中使用它,ListView中的每个项目都有一个进度滑块来更新目标进度
我现在不确定如何处理持久数据
我目前的做法是包装模型属性,并在更新这些属性时保存数据。这看起来很混乱:
class GoalState with ChangeNotifier {
set progress(int progress) {
_goal.progress = progress;
database.updateGoal(_goal);
notifyListeners();
}
int get progress => _goal.progress;
Goal _goal;
GoalState(this._goal);
}
这个问题的好模式是什么
class GoalState with ChangeNotifier {
set progress(int progress) {
_goal.progress = progress;
database.updateGoal(_goal);
notifyListeners();
}
int get progress => _goal.progress;
Goal _goal;
GoalState(this._goal);
}