CAKE-158 | removed isFirstAddress from wallet_address_list_view_model.dart; rename isFirstAddress property of AddressCell on isPrimary; defined primary address cell in the receive_page.dart

OleksandrSobol committed Dec 3, 2020 at 22:06 UTC a5d5831d993e18ab0e58c7ccd491faa07bc48a8a
3 files changed +89 -88
lib/src/screens/receive/receive_page.dart
+84 -79
@@ -95,85 +95,90 @@ class ReceivePage extends BasePage {
95 amountTextFieldFocusNode: _cryptoAmountFocus),
96 ),
97 Observer(
98 - builder: (_) => ListView.separated(
99 - padding: EdgeInsets.all(0),
100 - separatorBuilder: (context, _) => Container(
101 - height: 1, color: Theme.of(context).dividerColor),
102 - shrinkWrap: true,
103 - physics: NeverScrollableScrollPhysics(),
104 - itemCount: addressListViewModel.items.length,
105 - itemBuilder: (context, index) {
106 - final item = addressListViewModel.items[index];
107 - Widget cell = Container();
108 -
109 - if (item is WalletAccountListHeader) {
110 - cell = HeaderTile(
111 - onTap: () async => await showPopUp<void>(
112 - context: context,
113 - builder: (_) =>
114 - getIt.get<MoneroAccountListPage>()),
115 - title: S.of(context).accounts,
116 - icon: Icon(
117 - Icons.arrow_forward_ios,
118 - size: 14,
119 - color:
120 - Theme.of(context).textTheme.display1.color,
121 - ));
122 - }
123 -
124 - if (item is WalletAddressListHeader) {
125 - cell = HeaderTile(
126 - onTap: () => Navigator.of(context)
127 - .pushNamed(Routes.newSubaddress),
128 - title: S.of(context).addresses,
129 - icon: Icon(
130 - Icons.add,
131 - size: 20,
132 - color:
133 - Theme.of(context).textTheme.display1.color,
134 - ));
135 - }
136 -
137 - if (item is WalletAddressListItem) {
138 - final isFirst = addressListViewModel.isFirstAddress;
139 - addressListViewModel.isFirstAddress = false;
140 - cell = Observer(builder: (_) {
141 - final isCurrent = item.address ==
142 - addressListViewModel.address.address;
143 - final backgroundColor = isCurrent
144 - ? Theme.of(context)
145 - .textTheme
146 - .display3
147 - .decorationColor
148 - : Theme.of(context)
149 - .textTheme
150 - .display2
151 - .decorationColor;
152 - final textColor = isCurrent
153 - ? Theme.of(context).textTheme.display3.color
154 - : Theme.of(context).textTheme.display2.color;
155 -
156 - return AddressCell.fromItem(item,
157 - isCurrent: isCurrent,
158 - isFirstAddress: isFirst,
159 - backgroundColor: backgroundColor,
160 - textColor: textColor,
161 - onTap: (_) => addressListViewModel.setAddress(item),
162 - onEdit: () => Navigator.of(context).pushNamed(
163 - Routes.newSubaddress,
164 - arguments: item));
165 - });
166 - }
167 -
168 - return index != 0
169 - ? cell
170 - : ClipRRect(
171 - borderRadius: BorderRadius.only(
172 - topLeft: Radius.circular(30),
173 - topRight: Radius.circular(30)),
174 - child: cell,
175 - );
176 - })),
98 + builder: (_) {
99 + var isPrimaryAddress = true;
100 +
101 + return ListView.separated(
102 + padding: EdgeInsets.all(0),
103 + separatorBuilder: (context, _) => Container(
104 + height: 1, color: Theme.of(context).dividerColor),
105 + shrinkWrap: true,
106 + physics: NeverScrollableScrollPhysics(),
107 + itemCount: addressListViewModel.items.length,
108 + itemBuilder: (context, index) {
109 + final item = addressListViewModel.items[index];
110 + Widget cell = Container();
111 +
112 + if (item is WalletAccountListHeader) {
113 + cell = HeaderTile(
114 + onTap: () async => await showPopUp<void>(
115 + context: context,
116 + builder: (_) =>
117 + getIt.get<MoneroAccountListPage>()),
118 + title: S.of(context).accounts,
119 + icon: Icon(
120 + Icons.arrow_forward_ios,
121 + size: 14,
122 + color:
123 + Theme.of(context).textTheme.display1.color,
124 + ));
125 + }
126 +
127 + if (item is WalletAddressListHeader) {
128 + cell = HeaderTile(
129 + onTap: () => Navigator.of(context)
130 + .pushNamed(Routes.newSubaddress),
131 + title: S.of(context).addresses,
132 + icon: Icon(
133 + Icons.add,
134 + size: 20,
135 + color:
136 + Theme.of(context).textTheme.display1.color,
137 + ));
138 + }
139 +
140 + if (item is WalletAddressListItem) {
141 + final isPrimary = isPrimaryAddress;
142 + isPrimaryAddress = false;
143 +
144 + cell = Observer(builder: (_) {
145 + final isCurrent = item.address ==
146 + addressListViewModel.address.address;
147 + final backgroundColor = isCurrent
148 + ? Theme.of(context)
149 + .textTheme
150 + .display3
151 + .decorationColor
152 + : Theme.of(context)
153 + .textTheme
154 + .display2
155 + .decorationColor;
156 + final textColor = isCurrent
157 + ? Theme.of(context).textTheme.display3.color
158 + : Theme.of(context).textTheme.display2.color;
159 +
160 + return AddressCell.fromItem(item,
161 + isCurrent: isCurrent,
162 + isPrimary: isPrimary,
163 + backgroundColor: backgroundColor,
164 + textColor: textColor,
165 + onTap: (_) => addressListViewModel.setAddress(item),
166 + onEdit: () => Navigator.of(context).pushNamed(
167 + Routes.newSubaddress,
168 + arguments: item));
169 + });
170 + }
171 +
172 + return index != 0
173 + ? cell
174 + : ClipRRect(
175 + borderRadius: BorderRadius.only(
176 + topLeft: Radius.circular(30),
177 + topRight: Radius.circular(30)),
178 + child: cell,
179 + );
180 + });
181 + }),
182 ],
183 ),
184 ));
lib/src/screens/receive/widgets/address_cell.dart
+5 -5
@@ -6,7 +6,7 @@ import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_i
6 class AddressCell extends StatelessWidget {
7 factory AddressCell.fromItem(WalletAddressListItem item,
8 {@required bool isCurrent,
9 - @required bool isFirstAddress,
9 + @required bool isPrimary,
10 @required Color backgroundColor,
11 @required Color textColor,
12 Function(String) onTap,
@@ -15,7 +15,7 @@ class AddressCell extends StatelessWidget {
15 address: item.address,
16 name: item.name,
17 isCurrent: isCurrent,
18 - isFirstAddress: isFirstAddress,
18 + isPrimary: isPrimary,
19 backgroundColor: backgroundColor,
20 textColor: textColor,
21 onTap: onTap,
@@ -25,7 +25,7 @@ class AddressCell extends StatelessWidget {
25 {@required this.address,
26 @required this.name,
27 @required this.isCurrent,
28 - @required this.isFirstAddress,
28 + @required this.isPrimary,
29 @required this.backgroundColor,
30 @required this.textColor,
31 this.onTap,
@@ -34,7 +34,7 @@ class AddressCell extends StatelessWidget {
34 final String address;
35 final String name;
36 final bool isCurrent;
37 - final bool isFirstAddress;
37 + final bool isPrimary;
38 final Color backgroundColor;
39 final Color textColor;
40 final Function(String) onTap;
@@ -60,7 +60,7 @@ class AddressCell extends StatelessWidget {
60 ),
61 ));
62
63 - return (isCurrent || isFirstAddress)
63 + return (isCurrent || isPrimary)
64 ? cell
65 : Slidable(
66 key: Key(address),
lib/view_model/wallet_address_list/wallet_address_list_view_model.dart
-4
@@ -67,9 +67,6 @@ abstract class WalletAddressListViewModelBase with Store {
67 @observable
68 String amount;
69
70 - @observable
71 - bool isFirstAddress;
72 -
70 @computed
71 WalletType get type => _wallet.type;
72
@@ -100,7 +97,6 @@ abstract class WalletAddressListViewModelBase with Store {
97 final addressList = ObservableList<ListItem>();
98
99 if (wallet is MoneroWallet) {
103 - isFirstAddress = true;
100 addressList.addAll(wallet.subaddressList.subaddresses.map((subaddress) =>
101 WalletAddressListItem(
102 id: subaddress.id,