diff --git a/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart b/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart index 6f5d730d7..a0c561e3c 100644 --- a/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart +++ b/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart @@ -2,7 +2,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; +import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/utilities/constants.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/rounded_container.dart'; import 'package:stackwallet/widgets/wallet_info_row/wallet_info_row.dart'; @@ -10,13 +12,16 @@ import 'package:stackwallet/widgets/wallet_info_row/wallet_info_row.dart'; class CoinWalletsTable extends ConsumerWidget { const CoinWalletsTable({ Key? key, - required this.walletIds, + required this.coin, }) : super(key: key); - final List walletIds; + final Coin coin; @override Widget build(BuildContext context, WidgetRef ref) { + final walletIds = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getWalletIdsFor(coin: coin))); + return Container( decoration: BoxDecoration( color: Theme.of(context).extension()!.popupBG, @@ -38,7 +43,7 @@ class CoinWalletsTable extends ConsumerWidget { children: [ if (i != 0) const SizedBox( - height: 32, + height: 8, ), Stack( children: [ diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart index 10b4c67e4..40a72f6e0 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart @@ -23,6 +23,7 @@ class WalletSummaryTable extends ConsumerStatefulWidget { class _WalletTableState extends ConsumerState { @override Widget build(BuildContext context) { + debugPrint("BUILD: $runtimeType"); final providersByCoin = ref .watch( walletsChangeNotifierProvider.select( @@ -35,72 +36,75 @@ class _WalletTableState extends ConsumerState { return TableView( rows: [ for (int i = 0; i < providersByCoin.length; i++) - TableViewRow( - padding: const EdgeInsets.symmetric( - horizontal: 20, - vertical: 16, - ), - decoration: BoxDecoration( - color: Theme.of(context).extension()!.popupBG, - borderRadius: BorderRadius.circular( - Constants.size.circularBorderRadius, - ), - ), - cells: [ - TableViewCell( - flex: 4, - child: Row( - children: [ - SvgPicture.asset( - Assets.svg.iconFor(coin: providersByCoin[i].key), - width: 28, - height: 28, + Builder( + builder: (context) { + final providers = ref.watch(walletsChangeNotifierProvider.select( + (value) => value + .getManagerProvidersForCoin(providersByCoin[i].key))); + + return TableViewRow( + padding: const EdgeInsets.symmetric( + horizontal: 20, + vertical: 16, + ), + decoration: BoxDecoration( + color: Theme.of(context).extension()!.popupBG, + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + ), + cells: [ + TableViewCell( + flex: 4, + child: Row( + children: [ + SvgPicture.asset( + Assets.svg.iconFor(coin: providersByCoin[i].key), + width: 28, + height: 28, + ), + const SizedBox( + width: 10, + ), + Text( + providersByCoin[i].key.prettyName, + style: STextStyles.desktopTextExtraSmall(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textDark, + ), + ) + ], ), - const SizedBox( - width: 10, - ), - Text( - providersByCoin[i].key.prettyName, + ), + TableViewCell( + flex: 4, + child: Text( + providers.length == 1 + ? "${providers.length} wallet" + : "${providers.length} wallets", style: STextStyles.desktopTextExtraSmall(context).copyWith( color: Theme.of(context) .extension()! - .textDark, + .textSubtitle1, ), - ) - ], - ), - ), - TableViewCell( - flex: 4, - child: Text( - providersByCoin[i].value.length == 1 - ? "${providersByCoin[i].value.length} wallet" - : "${providersByCoin[i].value.length} wallets", - style: STextStyles.desktopTextExtraSmall(context).copyWith( - color: Theme.of(context) - .extension()! - .textSubtitle1, + ), ), - ), - ), - TableViewCell( - flex: 6, - child: TablePriceInfo( + TableViewCell( + flex: 6, + child: TablePriceInfo( + coin: providersByCoin[i].key, + ), + ), + ], + expandingChild: CoinWalletsTable( coin: providersByCoin[i].key, ), - ), - ], - expandingChild: CoinWalletsTable( - walletIds: ref.watch( - walletsChangeNotifierProvider.select( - (value) => value.getWalletIdsFor( - coin: providersByCoin[i].key, - ), - ), - ), - ), - ) + ); + }, + ), ], ); } diff --git a/lib/services/wallets.dart b/lib/services/wallets.dart index cebba2ce5..da9f70a63 100644 --- a/lib/services/wallets.dart +++ b/lib/services/wallets.dart @@ -73,6 +73,17 @@ class Wallets extends ChangeNotifier { return result; } + List> getManagerProvidersForCoin(Coin coin) { + List> result = []; + for (final manager in _managerMap.values) { + if (manager.coin == coin) { + result.add(_managerProviderMap[manager.walletId] + as ChangeNotifierProvider); + } + } + return result; + } + ChangeNotifierProvider getManagerProvider(String walletId) { return _managerProviderMap[walletId] as ChangeNotifierProvider; } diff --git a/lib/widgets/table_view/table_view.dart b/lib/widgets/table_view/table_view.dart index 8c2d470bd..ed1bc8cf7 100644 --- a/lib/widgets/table_view/table_view.dart +++ b/lib/widgets/table_view/table_view.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -class TableView extends StatefulWidget { +class TableView extends StatelessWidget { const TableView({ Key? key, required this.rows, @@ -11,25 +11,26 @@ class TableView extends StatefulWidget { final List rows; final double rowSpacing; final bool shrinkWrap; - - @override - State createState() => _TableViewState(); -} - -class _TableViewState extends State { +// +// @override +// State createState() => _TableViewState(); +// } +// +// class _TableViewState extends State { @override Widget build(BuildContext context) { + debugPrint("BUILD: $runtimeType"); return ListView( - shrinkWrap: widget.shrinkWrap, + shrinkWrap: shrinkWrap, children: [ - for (int i = 0; i < widget.rows.length; i++) + for (int i = 0; i < rows.length; i++) Column( children: [ if (i != 0) SizedBox( - height: widget.rowSpacing, + height: rowSpacing, ), - widget.rows[i], + rows[i], ], ) ], diff --git a/lib/widgets/table_view/table_view_row.dart b/lib/widgets/table_view/table_view_row.dart index 9c3175efe..2bfc9d0c2 100644 --- a/lib/widgets/table_view/table_view_row.dart +++ b/lib/widgets/table_view/table_view_row.dart @@ -28,40 +28,21 @@ class TableViewRow extends StatefulWidget { } class _TableViewRowState extends State { - late final List cells; - late final Widget? expandingChild; - late final BoxDecoration? decoration; - late final void Function(ExpandableState)? onExpandChanged; - late final EdgeInsetsGeometry padding; - late final double spacing; - late final CrossAxisAlignment crossAxisAlignment; - bool _hovering = false; - @override - void initState() { - cells = widget.cells; - expandingChild = widget.expandingChild; - decoration = widget.decoration; - onExpandChanged = widget.onExpandChanged; - padding = widget.padding; - spacing = widget.spacing; - crossAxisAlignment = widget.crossAxisAlignment; - super.initState(); - } - @override Widget build(BuildContext context) { + debugPrint("BUILD: $runtimeType"); return Container( decoration: !_hovering - ? decoration - : decoration?.copyWith( + ? widget.decoration + : widget.decoration?.copyWith( boxShadow: [ Theme.of(context).extension()!.standardBoxShadow, Theme.of(context).extension()!.standardBoxShadow, ], ), - child: expandingChild == null + child: widget.expandingChild == null ? MouseRegion( onEnter: (_) { setState(() { @@ -74,18 +55,18 @@ class _TableViewRowState extends State { }); }, child: Padding( - padding: padding, + padding: widget.padding, child: Row( - crossAxisAlignment: crossAxisAlignment, + crossAxisAlignment: widget.crossAxisAlignment, children: [ - for (int i = 0; i < cells.length; i++) ...[ - if (i != 0 && i != cells.length) + for (int i = 0; i < widget.cells.length; i++) ...[ + if (i != 0 && i != widget.cells.length) SizedBox( - width: spacing, + width: widget.spacing, ), Expanded( - flex: cells[i].flex, - child: cells[i], + flex: widget.cells[i].flex, + child: widget.cells[i], ), ], ], @@ -93,7 +74,7 @@ class _TableViewRowState extends State { ), ) : Expandable( - onExpandChanged: onExpandChanged, + onExpandChanged: widget.onExpandChanged, header: MouseRegion( onEnter: (_) { setState(() { @@ -106,17 +87,17 @@ class _TableViewRowState extends State { }); }, child: Padding( - padding: padding, + padding: widget.padding, child: Row( children: [ - for (int i = 0; i < cells.length; i++) ...[ - if (i != 0 && i != cells.length) + for (int i = 0; i < widget.cells.length; i++) ...[ + if (i != 0 && i != widget.cells.length) SizedBox( - width: spacing, + width: widget.spacing, ), Expanded( - flex: cells[i].flex, - child: cells[i], + flex: widget.cells[i].flex, + child: widget.cells[i], ), ], ], @@ -132,7 +113,7 @@ class _TableViewRowState extends State { width: double.infinity, height: 1, ), - expandingChild!, + widget.expandingChild!, ], ), ),