diff --git a/lib/widgets/wallet_card.dart b/lib/widgets/wallet_card.dart index 6601774ce..31bba62a0 100644 --- a/lib/widgets/wallet_card.dart +++ b/lib/widgets/wallet_card.dart @@ -1,17 +1,10 @@ -import 'package:decimal/decimal.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_svg/flutter_svg.dart'; import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; import 'package:stackwallet/providers/providers.dart'; -import 'package:stackwallet/utilities/assets.dart'; -import 'package:stackwallet/utilities/cfcolors.dart'; import 'package:stackwallet/utilities/constants.dart'; -import 'package:stackwallet/utilities/enums/coin_enum.dart'; -import 'package:stackwallet/utilities/format.dart'; -import 'package:stackwallet/utilities/text_styles.dart'; -import 'package:stackwallet/widgets/animated_text.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; +import 'package:stackwallet/widgets/wallet_info_row/wallet_info_row.dart'; import 'package:tuple/tuple.dart'; class WalletSheetCard extends ConsumerWidget { @@ -26,15 +19,6 @@ class WalletSheetCard extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final manager = ref.watch(ref - .watch(walletsChangeNotifierProvider.notifier) - .getManagerProvider(walletId)); - - final locale = ref.watch( - localeServiceChangeNotifierProvider.select((value) => value.locale)); - - final coin = manager.coin; - return RoundedWhiteContainer( padding: const EdgeInsets.all(0), child: MaterialButton( @@ -58,69 +42,8 @@ class WalletSheetCard extends ConsumerWidget { .getManagerProvider(walletId)), ); }, - child: Row( - children: [ - Container( - decoration: BoxDecoration( - color: CFColors.coin.forCoin(manager.coin).withOpacity(0.5), - borderRadius: BorderRadius.circular( - Constants.size.circularBorderRadius, - ), - ), - child: Padding( - padding: const EdgeInsets.all(4), - child: SvgPicture.asset( - Assets.svg.iconFor(coin: coin), - width: 20, - height: 20, - ), - ), - ), - const SizedBox( - width: 12, - ), - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - manager.walletName, - style: STextStyles.titleBold12, - ), - const SizedBox( - height: 2, - ), - FutureBuilder( - future: manager.totalBalance, - builder: (builderContext, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - return Text( - "${Format.localizedStringAsFixed( - value: snapshot.data!, - locale: locale, - decimalPlaces: 8, - )} ${coin.ticker}", - style: STextStyles.itemSubtitle, - ); - } else { - return AnimatedText( - stringsToLoopThrough: const [ - "Loading balance", - "Loading balance.", - "Loading balance..", - "Loading balance..." - ], - style: STextStyles.itemSubtitle, - ); - } - }, - ), - ], - ), - ), - ], + child: WalletInfoRow( + walletId: walletId, ), ), ); diff --git a/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_balance_future.dart b/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_balance_future.dart new file mode 100644 index 000000000..53b88f208 --- /dev/null +++ b/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_balance_future.dart @@ -0,0 +1,65 @@ +import 'package:decimal/decimal.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:stackwallet/providers/providers.dart'; +import 'package:stackwallet/utilities/cfcolors.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/format.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/animated_text.dart'; + +class WalletInfoRowBalanceFuture extends ConsumerWidget { + const WalletInfoRowBalanceFuture({Key? key, required this.walletId}) + : super(key: key); + + final String walletId; + + @override + Widget build(BuildContext context, WidgetRef ref) { + final manager = ref.watch(ref + .watch(walletsChangeNotifierProvider.notifier) + .getManagerProvider(walletId)); + + final locale = ref.watch( + localeServiceChangeNotifierProvider.select( + (value) => value.locale, + ), + ); + + return FutureBuilder( + future: manager.totalBalance, + builder: (builderContext, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + return Text( + "${Format.localizedStringAsFixed( + value: snapshot.data!, + locale: locale, + decimalPlaces: 8, + )} ${manager.coin.ticker}", + style: Util.isDesktop + ? STextStyles.desktopTextExtraSmall.copyWith( + color: CFColors.textSubtitle1, + ) + : STextStyles.itemSubtitle, + ); + } else { + return AnimatedText( + stringsToLoopThrough: const [ + "Loading balance", + "Loading balance.", + "Loading balance..", + "Loading balance..." + ], + style: Util.isDesktop + ? STextStyles.desktopTextExtraSmall.copyWith( + color: CFColors.textSubtitle1, + ) + : STextStyles.itemSubtitle, + ); + } + }, + ); + } +} diff --git a/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart b/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart new file mode 100644 index 000000000..99ee86223 --- /dev/null +++ b/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/cfcolors.dart'; +import 'package:stackwallet/utilities/constants.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; + +class WalletInfoCoinIcon extends StatelessWidget { + const WalletInfoCoinIcon({Key? key, required this.coin}) : super(key: key); + + final Coin coin; + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + color: CFColors.coin.forCoin(coin).withOpacity(0.5), + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + ), + child: Padding( + padding: const EdgeInsets.all(4), + child: SvgPicture.asset( + Assets.svg.iconFor(coin: coin), + width: 20, + height: 20, + ), + ), + ); + } +} diff --git a/lib/widgets/wallet_info_row/wallet_info_row.dart b/lib/widgets/wallet_info_row/wallet_info_row.dart new file mode 100644 index 000000000..c58f59e1e --- /dev/null +++ b/lib/widgets/wallet_info_row/wallet_info_row.dart @@ -0,0 +1,93 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/providers/providers.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/cfcolors.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/wallet_info_row/sub_widgets/wallet_info_row_balance_future.dart'; +import 'package:stackwallet/widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart'; + +class WalletInfoRow extends ConsumerWidget { + const WalletInfoRow({ + Key? key, + required this.walletId, + this.onPressed, + }) : super(key: key); + + final String walletId; + final VoidCallback? onPressed; + + @override + Widget build(BuildContext context, WidgetRef ref) { + final manager = ref.watch(ref + .watch(walletsChangeNotifierProvider.notifier) + .getManagerProvider(walletId)); + + return Row( + children: Util.isDesktop + ? [ + Expanded( + flex: 4, + child: Row( + children: [ + WalletInfoCoinIcon(coin: manager.coin), + const SizedBox( + width: 12, + ), + Text( + manager.walletName, + style: STextStyles.desktopTextExtraSmall.copyWith( + color: CFColors.topNavPrimary, + ), + ), + ], + ), + ), + Expanded( + flex: 4, + child: WalletInfoRowBalanceFuture( + walletId: walletId, + ), + ), + Expanded( + flex: 6, + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + SvgPicture.asset( + Assets.svg.chevronDown, + width: 6, + height: 12, + color: CFColors.textSubtitle1, + ) + ], + ), + ) + ] + : [ + WalletInfoCoinIcon(coin: manager.coin), + const SizedBox( + width: 12, + ), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + manager.walletName, + style: STextStyles.titleBold12, + ), + const SizedBox( + height: 2, + ), + WalletInfoRowBalanceFuture(walletId: walletId), + ], + ), + ), + ], + ); + } +}