Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 使用可交互的listview项和提供程序模式持久化数据_Flutter_Dart - Fatal编程技术网

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);
}