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

This commit is contained in:
OleksandrSobol 2020-12-03 22:06:16 +02:00
parent e10387a1b6
commit a5d5831d99
3 changed files with 84 additions and 83 deletions

View file

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

View file

@ -67,9 +67,6 @@ abstract class WalletAddressListViewModelBase with Store {
@observable @observable
String amount; String amount;
@observable
bool isFirstAddress;
@computed @computed
WalletType get type => _wallet.type; WalletType get type => _wallet.type;
@ -100,7 +97,6 @@ abstract class WalletAddressListViewModelBase with Store {
final addressList = ObservableList<ListItem>(); final addressList = ObservableList<ListItem>();
if (wallet is MoneroWallet) { if (wallet is MoneroWallet) {
isFirstAddress = true;
addressList.addAll(wallet.subaddressList.subaddresses.map((subaddress) => addressList.addAll(wallet.subaddressList.subaddresses.map((subaddress) =>
WalletAddressListItem( WalletAddressListItem(
id: subaddress.id, id: subaddress.id,