fix wallets not showing up when more than 1 of the same type are created

This commit is contained in:
julian 2022-12-05 16:10:18 -06:00
parent 00f89e7d1b
commit ef8f38aeb8
5 changed files with 111 additions and 109 deletions

View file

@ -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<String> 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<StackColors>()!.popupBG,
@ -38,7 +43,7 @@ class CoinWalletsTable extends ConsumerWidget {
children: [
if (i != 0)
const SizedBox(
height: 32,
height: 8,
),
Stack(
children: [

View file

@ -23,6 +23,7 @@ class WalletSummaryTable extends ConsumerStatefulWidget {
class _WalletTableState extends ConsumerState<WalletSummaryTable> {
@override
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");
final providersByCoin = ref
.watch(
walletsChangeNotifierProvider.select(
@ -35,72 +36,75 @@ class _WalletTableState extends ConsumerState<WalletSummaryTable> {
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<StackColors>()!.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<StackColors>()!.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<StackColors>()!
.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<StackColors>()!
.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<StackColors>()!
.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,
),
),
),
),
)
);
},
),
],
);
}

View file

@ -73,6 +73,17 @@ class Wallets extends ChangeNotifier {
return result;
}
List<ChangeNotifierProvider<Manager>> getManagerProvidersForCoin(Coin coin) {
List<ChangeNotifierProvider<Manager>> result = [];
for (final manager in _managerMap.values) {
if (manager.coin == coin) {
result.add(_managerProviderMap[manager.walletId]
as ChangeNotifierProvider<Manager>);
}
}
return result;
}
ChangeNotifierProvider<Manager> getManagerProvider(String walletId) {
return _managerProviderMap[walletId] as ChangeNotifierProvider<Manager>;
}

View file

@ -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<Widget> rows;
final double rowSpacing;
final bool shrinkWrap;
@override
State<TableView> createState() => _TableViewState();
}
class _TableViewState extends State<TableView> {
//
// @override
// State<TableView> createState() => _TableViewState();
// }
//
// class _TableViewState extends State<TableView> {
@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],
],
)
],

View file

@ -28,40 +28,21 @@ class TableViewRow extends StatefulWidget {
}
class _TableViewRowState extends State<TableViewRow> {
late final List<TableViewCell> 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<StackColors>()!.standardBoxShadow,
Theme.of(context).extension<StackColors>()!.standardBoxShadow,
],
),
child: expandingChild == null
child: widget.expandingChild == null
? MouseRegion(
onEnter: (_) {
setState(() {
@ -74,18 +55,18 @@ class _TableViewRowState extends State<TableViewRow> {
});
},
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<TableViewRow> {
),
)
: Expandable(
onExpandChanged: onExpandChanged,
onExpandChanged: widget.onExpandChanged,
header: MouseRegion(
onEnter: (_) {
setState(() {
@ -106,17 +87,17 @@ class _TableViewRowState extends State<TableViewRow> {
});
},
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<TableViewRow> {
width: double.infinity,
height: 1,
),
expandingChild!,
widget.expandingChild!,
],
),
),