diff --git a/lib/pages/project/overview.dart b/lib/pages/project/overview.dart index 92e5e5b..949f300 100644 --- a/lib/pages/project/overview.dart +++ b/lib/pages/project/overview.dart @@ -25,12 +25,33 @@ class _ProjectOverviewPageState extends State ? _projects[_selectedDrawerIndex] : null; + List expandedList = []; + @override void afterFirstLayout(BuildContext context) { _loadProjects(); + VikunjaGlobal.of(context) + .settingsManager + .getExpandedProjects() + .then((val) => setState(() { + expandedList = val ?? []; + print("Setting expanded list in setup to $expandedList"); + })); } - List expandedList = []; + void updateExpandedList() { + VikunjaGlobal.of(context).settingsManager.setExpandedProjects(expandedList); + } + + void addToExpandedList(int id) { + expandedList.add(id); + updateExpandedList(); + } + + void removeFromExpandedList(int id) { + expandedList.remove(id); + updateExpandedList(); + } Widget createProjectTile(Project project, int level) { EdgeInsets insets = EdgeInsets.fromLTRB(level * 10 + 10, 0, 0, 0); @@ -65,9 +86,9 @@ class _ProjectOverviewPageState extends State ? () { setState(() { if (expanded) - expandedList.remove(project.id); + removeFromExpandedList(project.id); else - expandedList.add(project.id); + addToExpandedList(project.id); }); } : null, diff --git a/lib/service/services.dart b/lib/service/services.dart index 9434295..06d3a1d 100644 --- a/lib/service/services.dart +++ b/lib/service/services.dart @@ -246,6 +246,7 @@ class SettingsManager { "landing-page-due-date-tasks": "1", "sentry-enabled": "0", "sentry-modal-shown": "0", + "expanded-projects": "[]", }; void applydefaults() { @@ -325,11 +326,20 @@ class SettingsManager { } Future setPastServers(List? server) { - var val = jsonEncode(server); - print("val: $val"); return _storage.write(key: "recent-servers", value: jsonEncode(server)); } + Future?> getExpandedProjects() async { + String jsonString = await _storage.read(key: "expanded-projects") ?? "[]"; + List server = jsonDecode(jsonString); + return server.map((e) => e as int).toList(); + } + + Future setExpandedProjects(List? expandedProjects) { + return _storage.write( + key: "expanded-projects", value: jsonEncode(expandedProjects)); + } + Future getThemeMode() async { String? theme_mode = await _storage.read(key: "theme_mode"); if (theme_mode == null) setThemeMode(FlutterThemeMode.system);