Skip to content

Commit 4895320

Browse files
authored
🐛 Fix slowly loading task list when navigating from settings page (RubberDuckCrew#299)
2 parents 989f31f + 1e3d673 commit 4895320

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

lib/core/task_handler.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ class TaskHandler extends ChangeNotifier {
1919

2020
List<IssueLabel> _repoLabels = [];
2121

22+
bool _tasksLoading = false;
23+
bool _labelsLoading = false;
24+
25+
/// Whether the task handler is currently loading task data.
26+
bool get tasksLoading => _tasksLoading;
27+
28+
/// Whether the task handler is currently loading label data.
29+
bool get labelsLoading => _labelsLoading;
30+
2231
/// The list of all tasks available in the repository.
2332
List<Task> get tasks => List.unmodifiable(_tasks);
2433

@@ -28,11 +37,14 @@ class TaskHandler extends ChangeNotifier {
2837
/// The list of all tasks available in the repository.
2938
/// After the notification the current list of task is stored in [tasks].
3039
Future<void> loadTasks() async {
40+
_tasksLoading = true;
41+
notifyListeners();
3142
try {
3243
final RepositoryDetails? repo = await SettingsHandler()
3344
.getSelectedRepository();
3445
if (repo == null) {
3546
Logger.logWarning("No repository selected", _classId);
47+
_tasksLoading = false;
3648
return;
3749
}
3850
final List<Task> issues = await _fetchIssuesForRepository(repo);
@@ -49,13 +61,16 @@ class TaskHandler extends ChangeNotifier {
4961
Logger.logError("Failed to load tasks", _classId, e);
5062
} finally {
5163
Logger.logInfo("Loaded ${_tasks.length} tasks from repository", _classId);
64+
_tasksLoading = false;
5265
notifyListeners();
5366
}
5467
}
5568

5669
/// The list of all labels available in the repository.
5770
/// After the notification the current list of labels is stored in [repoLabels].
5871
Future<void> loadLabels() async {
72+
_labelsLoading = true;
73+
notifyListeners();
5974
try {
6075
_repoLabels.clear();
6176
final RepositoryDetails? repo = await SettingsHandler()
@@ -71,9 +86,11 @@ class TaskHandler extends ChangeNotifier {
7186
"Loaded ${_repoLabels.length} labels from repository ${repo.toSlug()}",
7287
_classId,
7388
);
74-
notifyListeners();
7589
} on Exception catch (e) {
7690
Logger.logError("Failed to load labels", _classId, e);
91+
} finally {
92+
_labelsLoading = false;
93+
notifyListeners();
7794
}
7895
}
7996

lib/ui/main_screen.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ class _MainScreenState extends State<MainScreen> {
2020
child: Consumer<MainScreenViewModel>(
2121
builder: (final context, final viewModel, final child) => Scaffold(
2222
appBar: const NormalAppBar(),
23-
body: switch (viewModel.selectedIndex) {
24-
0 => const TaskListView(),
25-
1 => const SettingsView(),
26-
_ => const TaskListView(),
27-
},
23+
body: IndexedStack(
24+
index: viewModel.selectedIndex,
25+
children: const [TaskListView(), SettingsView()],
26+
),
2827
bottomNavigationBar: NavigationBar(
2928
destinations: const [
3029
NavigationDestination(icon: Icon(Icons.inbox), label: "Todos"),

lib/ui/settings/widgets/repository_selector/repository_selector_view_model.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "package:flutter/material.dart";
22
import "package:gitdone/core/models/repository_details.dart";
3+
import "package:gitdone/core/task_handler.dart";
34
import "package:gitdone/ui/settings/widgets/repository_selector/repository_selector_model.dart";
45

56
/// ViewModel for managing the state of the repository selector widget.
@@ -11,6 +12,7 @@ class RepositorySelectorViewModel extends ChangeNotifier {
1112
..getAllUserRepositories()
1213
..loadLocalRepository();
1314
}
15+
final TaskHandler _taskHandler = TaskHandler();
1416
final RepositorySelectorModel _model = RepositorySelectorModel();
1517

1618
/// The list of repositories available for selection.
@@ -22,5 +24,8 @@ class RepositorySelectorViewModel extends ChangeNotifier {
2224
/// Selects a repository and saves it to local storage.
2325
void selectRepository(final RepositoryDetails? repo) {
2426
_model.selectRepository(repo);
27+
_taskHandler
28+
..loadTasks()
29+
..loadLabels();
2530
}
2631
}

lib/ui/task_list/task_list_view_model.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class TaskListViewModel extends ChangeNotifier {
6262
/// The current sort order applied to the task list.
6363
String _sort = defaultSort;
6464
bool _isEmpty = false;
65-
bool _loading = true;
6665

6766
static const _classId =
6867
"com.GitDone.gitdone.ui.task_edit.task_list_view_model";
@@ -80,7 +79,7 @@ class TaskListViewModel extends ChangeNotifier {
8079
bool get isEmpty => _isEmpty;
8180

8281
/// Whether the task list is currently loading.
83-
bool get isLoading => _loading;
82+
bool get isLoading => _taskHandler.tasksLoading;
8483

8584
/// Returns a list of FilterChipItems for all labels, reflecting current selection state.
8685
List<FilterChipItem<String>> get labelFilterChipItems => allLabels.isNotEmpty
@@ -132,11 +131,8 @@ class TaskListViewModel extends ChangeNotifier {
132131

133132
/// The current search query used to filter tasks.
134133
Future<void> loadTasks() async {
135-
_loading = true;
136-
notifyListeners();
137134
await _taskHandler.loadTasks();
138135
_isEmpty = _taskHandler.tasks.isEmpty;
139-
_loading = false;
140136
notifyListeners();
141137
}
142138

0 commit comments

Comments
 (0)