"<p>In this Flutter Tutorial we are going to see how to move tasks from Todo to Done shared preferences when the task is marked as done. We are using the shared_preferences package for this.Then we will refactor our code and test our application.</p> <p>To complete this task, we created two methods  : </p> <p><strong>1. syncDoneTaskToCache(Task _task)</strong><br /> <br />  This method allow us to synchronize the cache by retreiving todoTasks,removing the marked task from it and update the cache, then we retreive done tasks from cache,   add the marked task adn finally update the cache.</p> <pre> <code>void syncDoneTaskToCache(Task _task) async { final prefs = await SharedPreferences.getInstance(); List<Task> _tasksList = []; List<Task> _doneList = []; // Retrieve all todoTasks from cache _tasksList = await getCacheValuesByKey(globals.todoTasksKey); // remove todoTask from prefs _tasksList.removeWhere((element) => element.id == _task.id); // update todoTask cache await prefs.setString(globals.todoTasksKey, json.encode(_tasksList));</code> // Retrieve all doneTasks from cache _doneList = await getCacheValuesByKey(globals.doneTasksKey); // add doneTask from prefs _doneList.add(_task); // update doneTask cache await prefs.setString(globals.doneTasksKey, json.encode(_doneList)); final String? testData = prefs.getString(globals.doneTasksKey); print(testData!); } </pre> <p> </p> <p><strong>2. getCacheValuesByKey(String key)</strong></p> <p> Since we duplicated the code when we are retreiving data from cache, we can wrap the code in this function and pass the preferred key.</p> <pre> <code>Future<List<Task>> getCacheValuesByKey(String key) async { final prefs = await SharedPreferences.getInstance(); if (prefs.containsKey(key)) { final String? data = prefs.getString(key); List<dynamic> _oldTasks = json.decode(data!); return List<Task>.from( _oldTasks.map((element) => Task.fromJson(element))); } return []; }</code></pre>"