CAKE-158 | added isPrimary property to WalletAddressListItem; removed defining primary address cell in the receive_page.dart

This commit is contained in:
OleksandrSobol 2020-12-03 22:47:00 +02:00
parent a5d5831d99
commit b200c56c58
4 changed files with 94 additions and 90 deletions

View file

@ -95,90 +95,82 @@ class ReceivePage extends BasePage {
amountTextFieldFocusNode: _cryptoAmountFocus), amountTextFieldFocusNode: _cryptoAmountFocus),
), ),
Observer( Observer(
builder: (_) { builder: (_) => ListView.separated(
var isPrimaryAddress = true; padding: EdgeInsets.all(0),
separatorBuilder: (context, _) => Container(
height: 1, color: Theme.of(context).dividerColor),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: addressListViewModel.items.length,
itemBuilder: (context, index) {
final item = addressListViewModel.items[index];
Widget cell = Container();
return ListView.separated( if (item is WalletAccountListHeader) {
padding: EdgeInsets.all(0), cell = HeaderTile(
separatorBuilder: (context, _) => Container( onTap: () async => await showPopUp<void>(
height: 1, color: Theme.of(context).dividerColor), context: context,
shrinkWrap: true, builder: (_) =>
physics: NeverScrollableScrollPhysics(), getIt.get<MoneroAccountListPage>()),
itemCount: addressListViewModel.items.length, title: S.of(context).accounts,
itemBuilder: (context, index) { icon: Icon(
final item = addressListViewModel.items[index]; Icons.arrow_forward_ios,
Widget cell = Container(); size: 14,
color:
Theme.of(context).textTheme.display1.color,
));
}
if (item is WalletAccountListHeader) { if (item is WalletAddressListHeader) {
cell = HeaderTile( cell = HeaderTile(
onTap: () async => await showPopUp<void>( onTap: () => Navigator.of(context)
context: context, .pushNamed(Routes.newSubaddress),
builder: (_) => title: S.of(context).addresses,
getIt.get<MoneroAccountListPage>()), icon: Icon(
title: S.of(context).accounts, Icons.add,
icon: Icon( size: 20,
Icons.arrow_forward_ios, color:
size: 14, Theme.of(context).textTheme.display1.color,
color: ));
Theme.of(context).textTheme.display1.color, }
));
}
if (item is WalletAddressListHeader) { if (item is WalletAddressListItem) {
cell = HeaderTile( cell = Observer(builder: (_) {
onTap: () => Navigator.of(context) final isCurrent = item.address ==
.pushNamed(Routes.newSubaddress), addressListViewModel.address.address;
title: S.of(context).addresses, final backgroundColor = isCurrent
icon: Icon( ? Theme.of(context)
Icons.add, .textTheme
size: 20, .display3
color: .decorationColor
Theme.of(context).textTheme.display1.color, : Theme.of(context)
)); .textTheme
} .display2
.decorationColor;
final textColor = isCurrent
? Theme.of(context).textTheme.display3.color
: Theme.of(context).textTheme.display2.color;
if (item is WalletAddressListItem) { return AddressCell.fromItem(item,
final isPrimary = isPrimaryAddress; isCurrent: isCurrent,
isPrimaryAddress = false; backgroundColor: backgroundColor,
textColor: textColor,
onTap: (_) => addressListViewModel.setAddress(item),
onEdit: () => Navigator.of(context).pushNamed(
Routes.newSubaddress,
arguments: item));
});
}
cell = Observer(builder: (_) { return index != 0
final isCurrent = item.address == ? cell
addressListViewModel.address.address; : ClipRRect(
final backgroundColor = isCurrent borderRadius: BorderRadius.only(
? Theme.of(context) topLeft: Radius.circular(30),
.textTheme topRight: Radius.circular(30)),
.display3 child: cell,
.decorationColor );
: Theme.of(context) })),
.textTheme
.display2
.decorationColor;
final textColor = isCurrent
? Theme.of(context).textTheme.display3.color
: Theme.of(context).textTheme.display2.color;
return AddressCell.fromItem(item,
isCurrent: isCurrent,
isPrimary: isPrimary,
backgroundColor: backgroundColor,
textColor: textColor,
onTap: (_) => addressListViewModel.setAddress(item),
onEdit: () => Navigator.of(context).pushNamed(
Routes.newSubaddress,
arguments: item));
});
}
return index != 0
? cell
: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30)),
child: cell,
);
});
}),
], ],
), ),
)); ));

View file

@ -6,7 +6,6 @@ import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_i
class AddressCell extends StatelessWidget { class AddressCell extends StatelessWidget {
factory AddressCell.fromItem(WalletAddressListItem item, factory AddressCell.fromItem(WalletAddressListItem item,
{@required bool isCurrent, {@required bool isCurrent,
@required bool isPrimary,
@required Color backgroundColor, @required Color backgroundColor,
@required Color textColor, @required Color textColor,
Function(String) onTap, Function(String) onTap,
@ -15,7 +14,7 @@ class AddressCell extends StatelessWidget {
address: item.address, address: item.address,
name: item.name, name: item.name,
isCurrent: isCurrent, isCurrent: isCurrent,
isPrimary: isPrimary, isPrimary: item.isPrimary,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
textColor: textColor, textColor: textColor,
onTap: onTap, onTap: onTap,

View file

@ -2,10 +2,11 @@ import 'package:flutter/foundation.dart';
import 'package:cake_wallet/utils/list_item.dart'; import 'package:cake_wallet/utils/list_item.dart';
class WalletAddressListItem extends ListItem { class WalletAddressListItem extends ListItem {
const WalletAddressListItem({@required this.address, this.name, this.id}) const WalletAddressListItem({@required this.address, @required this.isPrimary,
: super(); this.name, this.id}) : super();
final int id; final int id;
final bool isPrimary;
final String address; final String address;
final String name; final String name;

View file

@ -97,16 +97,28 @@ abstract class WalletAddressListViewModelBase with Store {
final addressList = ObservableList<ListItem>(); final addressList = ObservableList<ListItem>();
if (wallet is MoneroWallet) { if (wallet is MoneroWallet) {
addressList.addAll(wallet.subaddressList.subaddresses.map((subaddress) => final primaryAddress = wallet.subaddressList.subaddresses.first;
WalletAddressListItem( addressList.addAll(wallet.subaddressList.subaddresses.map((subaddress) {
id: subaddress.id, final isPrimary = subaddress == primaryAddress;
name: subaddress.label,
address: subaddress.address))); return WalletAddressListItem(
id: subaddress.id,
isPrimary: isPrimary,
name: subaddress.label,
address: subaddress.address);
}));
} }
if (wallet is BitcoinWallet) { if (wallet is BitcoinWallet) {
final bitcoinAddresses = wallet.addresses.map((addr) => final primaryAddress = wallet.addresses.first;
WalletAddressListItem(name: addr.label, address: addr.address)); final bitcoinAddresses = wallet.addresses.map((addr) {
final isPrimary = addr == primaryAddress;
return WalletAddressListItem(
isPrimary: isPrimary,
name: addr.label,
address: addr.address);
});
addressList.addAll(bitcoinAddresses); addressList.addAll(bitcoinAddresses);
} }