CW-471-Changing-nodes-bug (#1062)

* chore: Cleanup * fix: Node selection not updating * fix: Node selection not updating --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>

Adegoke David committed Sep 1, 2023 at 15:05 UTC 710fe82d7a7ba327b0b146400b0fbdfac0a32d24
2 files changed +32 -27
lib/src/screens/settings/manage_nodes_page.dart
+31 -27
@@ -42,36 +42,40 @@ class ManageNodesPage extends BasePage {
42 return nodeListViewModel.nodes.length;
43 },
44 itemBuilder: (_, index) {
45 - final node = nodeListViewModel.nodes[index];
46 - final isSelected = node.keyIndex == nodeListViewModel.currentNode.keyIndex;
47 - final nodeListRow = NodeListRow(
48 - title: node.uriRaw,
49 - node: node,
50 - isSelected: isSelected,
51 - onTap: (_) async {
52 - if (isSelected) {
53 - return;
54 - }
45 + return Observer(
46 + builder: (context) {
47 + final node = nodeListViewModel.nodes[index];
48 + final isSelected = node.keyIndex == nodeListViewModel.currentNode.keyIndex;
49 + final nodeListRow = NodeListRow(
50 + title: node.uriRaw,
51 + node: node,
52 + isSelected: isSelected,
53 + onTap: (_) async {
54 + if (isSelected) {
55 + return;
56 + }
57
56 - await showPopUp<void>(
57 - context: context,
58 - builder: (BuildContext context) {
59 - return AlertWithTwoActions(
60 - alertTitle: S.of(context).change_current_node_title,
61 - alertContent: nodeListViewModel.getAlertContent(node.uriRaw),
62 - leftButtonText: S.of(context).cancel,
63 - rightButtonText: S.of(context).change,
64 - actionLeftButton: () => Navigator.of(context).pop(),
65 - actionRightButton: () async {
66 - await nodeListViewModel.setAsCurrent(node);
67 - Navigator.of(context).pop();
68 - },
69 - );
70 - });
58 + await showPopUp<void>(
59 + context: context,
60 + builder: (BuildContext context) {
61 + return AlertWithTwoActions(
62 + alertTitle: S.of(context).change_current_node_title,
63 + alertContent: nodeListViewModel.getAlertContent(node.uriRaw),
64 + leftButtonText: S.of(context).cancel,
65 + rightButtonText: S.of(context).change,
66 + actionLeftButton: () => Navigator.of(context).pop(),
67 + actionRightButton: () async {
68 + await nodeListViewModel.setAsCurrent(node);
69 + Navigator.of(context).pop();
70 + },
71 + );
72 + },
73 + );
74 + },
75 + );
76 + return nodeListRow;
77 },
78 );
73 -
74 - return nodeListRow;
79 },
80 ),
81 );
lib/view_model/node_list/node_list_view_model.dart
+1
@@ -76,6 +76,7 @@ abstract class NodeListViewModelBase with Store {
76 @action
77 Future<void> delete(Node node) async => node.delete();
78
79 + @action
80 Future<void> setAsCurrent(Node node) async => settingsStore.nodes[_appStore.wallet!.type] = node;
81
82 @action