replace coin icons for swap + buy crypto select sheets

This commit is contained in:
ryleedavis 2023-05-04 13:26:46 -06:00
parent f4509dc70d
commit 90f5e6c369
3 changed files with 77 additions and 23 deletions

View file

@ -1,9 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/buy/response_objects/crypto.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/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.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/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.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/stack_text_field.dart';
import 'package:stackwallet/widgets/textfield_icon_button.dart'; import 'package:stackwallet/widgets/textfield_icon_button.dart';
class CryptoSelectionView extends StatefulWidget { class CryptoSelectionView extends ConsumerStatefulWidget {
const CryptoSelectionView({ const CryptoSelectionView({
Key? key, Key? key,
required this.coins, required this.coins,
@ -24,10 +27,11 @@ class CryptoSelectionView extends StatefulWidget {
final List<Crypto> coins; final List<Crypto> coins;
@override @override
State<CryptoSelectionView> createState() => _CryptoSelectionViewState(); ConsumerState<CryptoSelectionView> createState() =>
_CryptoSelectionViewState();
} }
class _CryptoSelectionViewState extends State<CryptoSelectionView> { class _CryptoSelectionViewState extends ConsumerState<CryptoSelectionView> {
late TextEditingController _searchController; late TextEditingController _searchController;
final _searchFocusNode = FocusNode(); final _searchFocusNode = FocusNode();
@ -197,9 +201,13 @@ class _CryptoSelectionViewState extends State<CryptoSelectionView> {
child: Row( child: Row(
children: [ children: [
SizedBox( SizedBox(
width: 24, width: 24,
height: 24, height: 24,
child: getIconForTicker(_coins[index].ticker)), child: CoinIconForTicker(
size: 20,
ticker: _coins[index].ticker,
),
),
const SizedBox( const SizedBox(
width: 10, width: 10,
), ),
@ -252,15 +260,56 @@ bool isStackCoin(String? ticker) {
} }
} }
Widget? getIconForTicker( // make a stateless widget that takes in string and double (won't ever be null)
String ticker, { // class getIconForTicker extends ConsumerWidget{
double size = 20, // const getIconForTicker({
}) { // Key? key,
String? iconAsset = /*isStackCoin(ticker) // this.ticker,
?*/ //
Assets.svg.iconFor(coin: coinFromTickerCaseInsensitive(ticker)); // }) : super(key: key);
// : Assets.svg.buyIconFor(ticker); // @override
return (iconAsset != null) // Widget build(BuildContext context, WidgetRef ref) {
? SvgPicture.asset(iconAsset, height: size, width: size) // // TODO: implement build
: null; // 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;
// }

View file

@ -373,10 +373,11 @@ class _ExchangeCurrencySelectionViewState
width: 24, width: 24,
height: 24, height: 24,
child: isStackCoin(items[index].ticker) child: isStackCoin(items[index].ticker)
? getIconForTicker( ? CoinIconForTicker(ticker: items[index].ticker, size: 24)
items[index].ticker, // ? getIconForTicker(
size: 24, // items[index].ticker,
) // size: 24,
// )
: hasImageUrl : hasImageUrl
? SvgPicture.network( ? SvgPicture.network(
items[index].image, items[index].image,

View file

@ -158,10 +158,14 @@ class _ExchangeTextFieldState extends State<ExchangeTextField> {
builder: (context) { builder: (context) {
if (isStackCoin(widget.currency?.ticker)) { if (isStackCoin(widget.currency?.ticker)) {
return Center( return Center(
child: getIconForTicker( child: CoinIconForTicker(
widget.currency!.ticker,
size: 18, size: 18,
ticker: widget.currency!.ticker,
), ),
// child: getIconForTicker(
// widget.currency!.ticker,
// size: 18,
// ),
); );
} else if (widget.currency != null && } else if (widget.currency != null &&
widget.currency!.image.isNotEmpty) { widget.currency!.image.isNotEmpty) {