diff --git a/lib/api/pulsar/pulsar_cluster_api.dart b/lib/api/pulsar/pulsar_cluster_api.dart index f851054..ae4d53c 100644 --- a/lib/api/pulsar/pulsar_cluster_api.dart +++ b/lib/api/pulsar/pulsar_cluster_api.dart @@ -17,9 +17,8 @@ class PulsarClusterAPi { } String version = versionResponse.body; - String tenantInfo = ""; - await PulsarTenantAPi.getTenantInfo(host, port, "public") - .then((value) => tenantInfo = value); + String tenantInfo = + await PulsarTenantAPi.getTenantInfo(host, port, "public"); String cluster = ((json.decode(tenantInfo) as Map)["allowedClusters"] as List)[0]; url = 'http://$host:${port.toString()}/admin/v2/brokers/$cluster'; @@ -40,11 +39,8 @@ class PulsarClusterAPi { } String leader = json.decode(leaderBrokerResponse.body)["serviceUrl"]; - List respList = new List.empty(growable: true); - brokers.forEach((element) { - respList.add(new ClusterResp( - element, leader.contains(element).toString(), version)); - }); - return respList; + return brokers + .map((e) => ClusterResp(e, leader.contains(e).toString(), version)) + .toList(); } } diff --git a/lib/vm/pulsar/pulsar_cluster_view_model.dart b/lib/vm/pulsar/pulsar_cluster_view_model.dart index 65f325a..3d77962 100644 --- a/lib/vm/pulsar/pulsar_cluster_view_model.dart +++ b/lib/vm/pulsar/pulsar_cluster_view_model.dart @@ -1,8 +1,7 @@ import 'package:paas_dashboard_flutter/api/pulsar/pulsar_cluster_api.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_cluster.dart'; import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart'; - -import '../base_load_list_page_view_model.dart'; +import 'package:paas_dashboard_flutter/vm/base_load_list_page_view_model.dart'; class PulsarClusterViewModel extends BaseLoadListPageViewModel { List instances = []; @@ -31,11 +30,11 @@ class PulsarClusterViewModel extends BaseLoadListPageViewModel { try { this.fullList = await PulsarClusterAPi.cluster(host, port); this.displayList = this.fullList; + loadSuccess(); } on Exception catch (e) { loadException = e; loading = false; } - loadSuccess(); notifyListeners(); }