From 90f5e6c369c68044fba17b34929be72eb2c50172 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Thu, 4 May 2023 13:26:46 -0600 Subject: [PATCH] replace coin icons for swap + buy crypto select sheets --- .../sub_widgets/crypto_selection_view.dart | 83 +++++++++++++++---- .../exchange_currency_selection_view.dart | 9 +- .../textfields/exchange_textfield.dart | 8 +- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart b/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart index f9d58a06b..a952bf8d8 100644 --- a/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart +++ b/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/models/buy/response_objects/crypto.dart'; +import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/util.dart'; @@ -15,7 +18,7 @@ import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/stack_text_field.dart'; import 'package:stackwallet/widgets/textfield_icon_button.dart'; -class CryptoSelectionView extends StatefulWidget { +class CryptoSelectionView extends ConsumerStatefulWidget { const CryptoSelectionView({ Key? key, required this.coins, @@ -24,10 +27,11 @@ class CryptoSelectionView extends StatefulWidget { final List coins; @override - State createState() => _CryptoSelectionViewState(); + ConsumerState createState() => + _CryptoSelectionViewState(); } -class _CryptoSelectionViewState extends State { +class _CryptoSelectionViewState extends ConsumerState { late TextEditingController _searchController; final _searchFocusNode = FocusNode(); @@ -197,9 +201,13 @@ class _CryptoSelectionViewState extends State { child: Row( children: [ SizedBox( - width: 24, - height: 24, - child: getIconForTicker(_coins[index].ticker)), + width: 24, + height: 24, + child: CoinIconForTicker( + size: 20, + ticker: _coins[index].ticker, + ), + ), const SizedBox( width: 10, ), @@ -252,15 +260,56 @@ bool isStackCoin(String? ticker) { } } -Widget? getIconForTicker( - String ticker, { - double size = 20, -}) { - String? iconAsset = /*isStackCoin(ticker) - ?*/ - Assets.svg.iconFor(coin: coinFromTickerCaseInsensitive(ticker)); - // : Assets.svg.buyIconFor(ticker); - return (iconAsset != null) - ? SvgPicture.asset(iconAsset, height: size, width: size) - : null; +// make a stateless widget that takes in string and double (won't ever be null) +// class getIconForTicker extends ConsumerWidget{ +// const getIconForTicker({ +// Key? key, +// this.ticker, +// +// }) : super(key: key); +// @override +// Widget build(BuildContext context, WidgetRef ref) { +// // TODO: implement build +// throw UnimplementedError(); +// } +// +// } +/// caller must ensure [Coin] for ticker exists +class CoinIconForTicker extends ConsumerWidget { + const CoinIconForTicker({ + Key? key, + required this.ticker, + required this.size, + }) : super(key: key); + + final String ticker; + final double size; + + @override + Widget build(BuildContext context, WidgetRef ref) { + try { + final coin = coinFromTickerCaseInsensitive(ticker); + return SvgPicture.asset( + ref.watch(coinIconProvider(coin)), + width: size, + height: size, + ); + } catch (e, s) { + Logging.instance.log("$e\n$s", level: LogLevel.Fatal); + rethrow; + } + } } + +// Widget? getIconForTicker( +// String ticker, { +// double size = 20, +// }) { +// String? iconAsset = /*isStackCoin(ticker) +// ?*/ +// Assets.svg.iconFor(coin: coinFromTickerCaseInsensitive(ticker)); +// // : Assets.svg.buyIconFor(ticker); +// return (iconAsset != null) +// ? SvgPicture.asset(iconAsset, height: size, width: size) +// : null; +// } diff --git a/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart b/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart index ffe7d0492..1fcb43b7e 100644 --- a/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart +++ b/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart @@ -373,10 +373,11 @@ class _ExchangeCurrencySelectionViewState width: 24, height: 24, child: isStackCoin(items[index].ticker) - ? getIconForTicker( - items[index].ticker, - size: 24, - ) + ? CoinIconForTicker(ticker: items[index].ticker, size: 24) + // ? getIconForTicker( + // items[index].ticker, + // size: 24, + // ) : hasImageUrl ? SvgPicture.network( items[index].image, diff --git a/lib/widgets/textfields/exchange_textfield.dart b/lib/widgets/textfields/exchange_textfield.dart index 33fc6d738..273221dc7 100644 --- a/lib/widgets/textfields/exchange_textfield.dart +++ b/lib/widgets/textfields/exchange_textfield.dart @@ -158,10 +158,14 @@ class _ExchangeTextFieldState extends State { builder: (context) { if (isStackCoin(widget.currency?.ticker)) { return Center( - child: getIconForTicker( - widget.currency!.ticker, + child: CoinIconForTicker( size: 18, + ticker: widget.currency!.ticker, ), + // child: getIconForTicker( + // widget.currency!.ticker, + // size: 18, + // ), ); } else if (widget.currency != null && widget.currency!.image.isNotEmpty) {