From 97eccf1b76cf40c4605420a11a91957bea461f6f Mon Sep 17 00:00:00 2001 From: shoothzj Date: Mon, 2 Aug 2021 11:36:18 +0800 Subject: [PATCH] Extract common method loadSuccess --- lib/vm/base_load_list_page_view_model.dart | 6 ++++++ lib/vm/base_load_view_model.dart | 6 ++++++ lib/vm/pulsar/pulsar_instance_view_model.dart | 3 +-- lib/vm/pulsar/pulsar_namespace_view_model.dart | 3 +-- lib/vm/pulsar/pulsar_partitioned_topic_view_model.dart | 3 +-- lib/vm/pulsar/pulsar_tenant_view_model.dart | 3 +-- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/vm/base_load_list_page_view_model.dart b/lib/vm/base_load_list_page_view_model.dart index 0768fa7..47ee13c 100644 --- a/lib/vm/base_load_list_page_view_model.dart +++ b/lib/vm/base_load_list_page_view_model.dart @@ -19,6 +19,12 @@ abstract class BaseLoadListPageViewModel extends DataTableSource { this.converter = converter; } + /// call loadSuccess to set loading to false and clear the exceptions + void loadSuccess() { + loading = false; + loadException = null; + } + @override DataRow? getRow(int index) { if (converter == null) { diff --git a/lib/vm/base_load_view_model.dart b/lib/vm/base_load_view_model.dart index b518974..5d3d396 100644 --- a/lib/vm/base_load_view_model.dart +++ b/lib/vm/base_load_view_model.dart @@ -6,4 +6,10 @@ class BaseLoadViewModel extends ChangeNotifier { Exception? loadException; Exception? opException; + + /// call loadSuccess to set loading to false and clear the exceptions + void loadSuccess() { + loading = false; + loadException = null; + } } diff --git a/lib/vm/pulsar/pulsar_instance_view_model.dart b/lib/vm/pulsar/pulsar_instance_view_model.dart index 818e78f..caf596a 100644 --- a/lib/vm/pulsar/pulsar_instance_view_model.dart +++ b/lib/vm/pulsar/pulsar_instance_view_model.dart @@ -38,8 +38,7 @@ class PulsarInstanceViewModel .map((e) => PulsarTenantViewModel(pulsarInstancePo, e)) .toList(); this.displayList = this.fullList; - loadException = null; - loading = false; + loadSuccess(); } on Exception catch (e) { log('request failed, $e'); loadException = e; diff --git a/lib/vm/pulsar/pulsar_namespace_view_model.dart b/lib/vm/pulsar/pulsar_namespace_view_model.dart index 999e3e2..a5956ff 100644 --- a/lib/vm/pulsar/pulsar_namespace_view_model.dart +++ b/lib/vm/pulsar/pulsar_namespace_view_model.dart @@ -52,8 +52,7 @@ class PulsarNamespaceViewModel pulsarInstancePo, tenantResp, namespaceResp, e)) .toList(); this.displayList = this.fullList; - loadException = null; - loading = false; + loadSuccess(); } on Exception catch (e) { loadException = e; loading = false; diff --git a/lib/vm/pulsar/pulsar_partitioned_topic_view_model.dart b/lib/vm/pulsar/pulsar_partitioned_topic_view_model.dart index 156820a..47a792c 100644 --- a/lib/vm/pulsar/pulsar_partitioned_topic_view_model.dart +++ b/lib/vm/pulsar/pulsar_partitioned_topic_view_model.dart @@ -54,8 +54,7 @@ class PulsarTopicViewModel extends BaseLoadListViewModel { host, port, tenant, namespace, topic); this.fullList = results; this.displayList = this.fullList; - loadException = null; - loading = false; + loadSuccess(); } on Exception catch (e) { loadException = e; loading = false; diff --git a/lib/vm/pulsar/pulsar_tenant_view_model.dart b/lib/vm/pulsar/pulsar_tenant_view_model.dart index 8ddb9e3..be2909d 100644 --- a/lib/vm/pulsar/pulsar_tenant_view_model.dart +++ b/lib/vm/pulsar/pulsar_tenant_view_model.dart @@ -47,8 +47,7 @@ class PulsarTenantViewModel .map((e) => PulsarNamespaceViewModel(pulsarInstancePo, tenantResp, e)) .toList(); this.displayList = this.fullList; - loadException = null; - loading = false; + loadSuccess(); } on Exception catch (e) { loadException = e; loading = false;