Conversation
- Add taskIndentLevels getter/setter to SharedPreferencesUtil for persistence - Load saved indent levels on ActionItemsPage init - Save indent levels when user swipes to indent/unindent tasks - Follows existing pattern for taskCategoryOrder and taskGoalLinks Fixes task indentation state not persisting after app restart Co-authored-by: Nik Shevchenko <kodjima33@users.noreply.github.com>
|
Cursor Agent can help with this pull request. Just |
There was a problem hiding this comment.
Code Review
This pull request adds persistence for task indentation levels, which is a great enhancement for user experience. The implementation correctly uses SharedPreferences to store and retrieve the indent levels. However, I've identified a high-severity issue where the indent level for a deleted task is not removed from storage, leading to an accumulation of stale data over time. My review includes a detailed comment on how to address this data leak.
| void _saveTaskIndentLevels() { | ||
| SharedPreferencesUtil().taskIndentLevels = Map<String, int>.from(_indentLevels); | ||
| } |
There was a problem hiding this comment.
The current implementation persists indent levels but doesn't handle cleaning up this data when a task is deleted. This will lead to stale data for deleted tasks accumulating in SharedPreferences over time.
To fix this, you should ensure that when a task is deleted, its corresponding entry in _indentLevels is also removed and the map is re-saved.
Since task deletion can be initiated from different places (e.g., swipe-to-delete on this page or from the ActionItemFormSheet), you'll need to handle cleanup in each case. For swipe-to-delete, you could modify the _deleteTask method:
Future<void> _deleteTask(ActionItemWithMetadata item) async {
HapticFeedback.mediumImpact();
final provider = Provider.of<ActionItemsProvider>(context, listen: false);
final success = await provider.deleteActionItem(item);
if (success && mounted) {
if (_indentLevels.remove(item.id) != null) {
_saveTaskIndentLevels();
}
}
}A similar approach would be needed for deletions from the edit sheet, likely by passing a callback.
| void _saveTaskIndentLevels() { | |
| SharedPreferencesUtil().taskIndentLevels = Map<String, int>.from(_indentLevels); | |
| } | |
| Future<void> _deleteTask(ActionItemWithMetadata item) async { | |
| HapticFeedback.mediumImpact(); | |
| final provider = Provider.of<ActionItemsProvider>(context, listen: false); | |
| final success = await provider.deleteActionItem(item); | |
| if (success && mounted) { | |
| if (_indentLevels.remove(item.id) != null) { | |
| _saveTaskIndentLevels(); | |
| } | |
| } | |
| } |
Persist task indent levels across app restarts to ensure indentation state is restored.