From 19c4c110ad5136fccded8ae06fca7b93bbc02519 Mon Sep 17 00:00:00 2001 From: Simone Stasi Date: Wed, 20 Dec 2023 13:39:02 +0100 Subject: [PATCH] fix handle multiple identical instances in memory This is done by avoid removing instance from cached _instances map on dispose. The bug happened when there were two identical pages in memory and one of them was disposed, thus removing the cached instance also for the other page instance and leaving a circular progress indicator spinning forever. --- lib/src/screens/commit_detail/controller_commit_detail.dart | 3 +-- lib/src/screens/commits/controller_commits.dart | 3 +-- lib/src/screens/member_detail/controller_member_detail.dart | 3 +-- .../screens/pipeline_detail/controller_pipeline_detail.dart | 3 +-- lib/src/screens/pipelines/controller_pipelines.dart | 3 +-- lib/src/screens/project_detail/controller_project_detail.dart | 4 ++-- .../pull_request_detail/controller_pull_request_detail.dart | 3 +-- lib/src/screens/pull_requests/controller_pull_requests.dart | 3 +-- .../repository_detail/controller_repository_detail.dart | 3 +-- .../screens/work_item_detail/controller_work_item_detail.dart | 3 +-- lib/src/screens/work_items/controller_work_items.dart | 3 +-- 11 files changed, 12 insertions(+), 22 deletions(-) diff --git a/lib/src/screens/commit_detail/controller_commit_detail.dart b/lib/src/screens/commit_detail/controller_commit_detail.dart index 9782a4bd..ab7c7718 100644 --- a/lib/src/screens/commit_detail/controller_commit_detail.dart +++ b/lib/src/screens/commit_detail/controller_commit_detail.dart @@ -8,7 +8,7 @@ class _CommitDetailController with ShareMixin { } if (instance != null && args.commitId != instance!.args.commitId) { - instance = _CommitDetailController._(args, apiService); + instance = null; } instance ??= _CommitDetailController._(args, apiService); @@ -46,7 +46,6 @@ class _CommitDetailController with ShareMixin { void dispose() { instance = null; - _instances.remove(args.hashCode); } Future init() async { diff --git a/lib/src/screens/commits/controller_commits.dart b/lib/src/screens/commits/controller_commits.dart index ca221ea1..8fbf8d82 100644 --- a/lib/src/screens/commits/controller_commits.dart +++ b/lib/src/screens/commits/controller_commits.dart @@ -12,7 +12,7 @@ class _CommitsController with FilterMixin { } if (instance != null && args != instance!.args) { - instance = _CommitsController._(apiService, storageService, args); + instance = null; } instance ??= _CommitsController._(apiService, storageService, args); @@ -40,7 +40,6 @@ class _CommitsController with FilterMixin { void dispose() { instance = null; - _instances.remove(args); } Future init() async { diff --git a/lib/src/screens/member_detail/controller_member_detail.dart b/lib/src/screens/member_detail/controller_member_detail.dart index 7c322582..b5fd46b0 100644 --- a/lib/src/screens/member_detail/controller_member_detail.dart +++ b/lib/src/screens/member_detail/controller_member_detail.dart @@ -8,7 +8,7 @@ class _MemberDetailController { } if (instance != null && instance!.userDescriptor != userDescriptor) { - instance = _MemberDetailController._(userDescriptor, apiService); + instance = null; } instance ??= _MemberDetailController._(userDescriptor, apiService); @@ -31,7 +31,6 @@ class _MemberDetailController { void dispose() { instance = null; - _instances.remove(userDescriptor); } Future init() async { diff --git a/lib/src/screens/pipeline_detail/controller_pipeline_detail.dart b/lib/src/screens/pipeline_detail/controller_pipeline_detail.dart index 38cc27f5..ffad6ddb 100644 --- a/lib/src/screens/pipeline_detail/controller_pipeline_detail.dart +++ b/lib/src/screens/pipeline_detail/controller_pipeline_detail.dart @@ -8,7 +8,7 @@ class _PipelineDetailController with ShareMixin { } if (instance != null && args.id != instance!.args.id) { - instance = _PipelineDetailController._(args, apiService); + instance = null; } instance ??= _PipelineDetailController._(args, apiService); @@ -39,7 +39,6 @@ class _PipelineDetailController with ShareMixin { _stopTimer(); instance = null; - _instances.remove(args.hashCode); } void _stopTimer() { diff --git a/lib/src/screens/pipelines/controller_pipelines.dart b/lib/src/screens/pipelines/controller_pipelines.dart index a6e88f5f..2de4d755 100644 --- a/lib/src/screens/pipelines/controller_pipelines.dart +++ b/lib/src/screens/pipelines/controller_pipelines.dart @@ -12,7 +12,7 @@ class _PipelinesController with FilterMixin { } if (instance != null && args != instance!.args) { - instance = _PipelinesController._(apiService, storageService, args); + instance = null; } instance ??= _PipelinesController._(apiService, storageService, args); @@ -53,7 +53,6 @@ class _PipelinesController with FilterMixin { _stopTimer(); instance = null; - _instances.remove(args.hashCode); } void _stopTimer() { diff --git a/lib/src/screens/project_detail/controller_project_detail.dart b/lib/src/screens/project_detail/controller_project_detail.dart index 3d5c131b..503c2a81 100644 --- a/lib/src/screens/project_detail/controller_project_detail.dart +++ b/lib/src/screens/project_detail/controller_project_detail.dart @@ -8,8 +8,9 @@ class _ProjectDetailController { } if (instance != null && instance!.projectName != projectName) { - instance = _ProjectDetailController._(apiService, projectName); + instance = null; } + instance ??= _ProjectDetailController._(apiService, projectName); return _instances.putIfAbsent(projectName, () => instance!); } @@ -37,7 +38,6 @@ class _ProjectDetailController { void dispose() { instance = null; - _instances.remove(projectName); } Future init() async { diff --git a/lib/src/screens/pull_request_detail/controller_pull_request_detail.dart b/lib/src/screens/pull_request_detail/controller_pull_request_detail.dart index 2427376e..63626717 100644 --- a/lib/src/screens/pull_request_detail/controller_pull_request_detail.dart +++ b/lib/src/screens/pull_request_detail/controller_pull_request_detail.dart @@ -11,7 +11,7 @@ class _PullRequestDetailController with ShareMixin, AppLogger, PullRequestHelper } if (instance != null && instance!.args != args) { - instance = _PullRequestDetailController._(args, apiService); + instance = null; } instance ??= _PullRequestDetailController._(args, apiService); @@ -65,7 +65,6 @@ class _PullRequestDetailController with ShareMixin, AppLogger, PullRequestHelper void dispose() { instance = null; - _instances.remove(args.hashCode); } Future init() async { diff --git a/lib/src/screens/pull_requests/controller_pull_requests.dart b/lib/src/screens/pull_requests/controller_pull_requests.dart index a711ed4b..e4834e47 100644 --- a/lib/src/screens/pull_requests/controller_pull_requests.dart +++ b/lib/src/screens/pull_requests/controller_pull_requests.dart @@ -12,7 +12,7 @@ class _PullRequestsController with FilterMixin { } if (instance != null && project?.id != instance!.project?.id) { - instance = _PullRequestsController._(apiService, storageService, project); + instance = null; } instance ??= _PullRequestsController._(apiService, storageService, project); @@ -47,7 +47,6 @@ class _PullRequestsController with FilterMixin { void dispose() { instance = null; - _instances.remove(project.hashCode); } Future init() async { diff --git a/lib/src/screens/repository_detail/controller_repository_detail.dart b/lib/src/screens/repository_detail/controller_repository_detail.dart index 45a144c8..6db96c6f 100644 --- a/lib/src/screens/repository_detail/controller_repository_detail.dart +++ b/lib/src/screens/repository_detail/controller_repository_detail.dart @@ -8,7 +8,7 @@ class _RepositoryDetailController { } if (instance != null && instance!.args != args) { - instance = _RepositoryDetailController._(apiService, args); + instance = null; } instance ??= _RepositoryDetailController._(apiService, args); @@ -33,7 +33,6 @@ class _RepositoryDetailController { void dispose() { instance = null; - _instances.remove(args.hashCode); } Future init() async { diff --git a/lib/src/screens/work_item_detail/controller_work_item_detail.dart b/lib/src/screens/work_item_detail/controller_work_item_detail.dart index 83f59428..ca03ce1b 100644 --- a/lib/src/screens/work_item_detail/controller_work_item_detail.dart +++ b/lib/src/screens/work_item_detail/controller_work_item_detail.dart @@ -12,7 +12,7 @@ class _WorkItemDetailController with ShareMixin, FilterMixin, AppLogger { } if (instance != null && instance!.args != args) { - instance = _WorkItemDetailController._(args, apiService, storageService); + instance = null; } instance ??= _WorkItemDetailController._(args, apiService, storageService); @@ -49,7 +49,6 @@ class _WorkItemDetailController with ShareMixin, FilterMixin, AppLogger { void dispose() { instance = null; - _instances.remove(args.hashCode); } Future init() async { diff --git a/lib/src/screens/work_items/controller_work_items.dart b/lib/src/screens/work_items/controller_work_items.dart index b4a78b5f..20c92e43 100644 --- a/lib/src/screens/work_items/controller_work_items.dart +++ b/lib/src/screens/work_items/controller_work_items.dart @@ -12,7 +12,7 @@ class _WorkItemsController with FilterMixin { } if (instance != null && project?.id != instance!.project?.id) { - instance = _WorkItemsController._(apiService, storageService, project); + instance = null; } instance ??= _WorkItemsController._(apiService, storageService, project); @@ -58,7 +58,6 @@ class _WorkItemsController with FilterMixin { void dispose() { instance = null; - _instances.remove(project.hashCode); } Future init() async {