stack_wallet/lib/widgets/icon_widgets/eth_token_icon.dart

65 lines
1.7 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:isar/isar.dart';
import '../../models/isar/exchange_cache/currency.dart';
import '../../services/exchange/exchange_data_loading_service.dart';
import '../../themes/coin_icon_provider.dart';
import '../../wallets/crypto_currency/crypto_currency.dart';
class EthTokenIcon extends ConsumerStatefulWidget {
const EthTokenIcon({
2024-05-15 21:20:45 +00:00
super.key,
required this.contractAddress,
2023-04-03 22:38:48 +00:00
this.size = 22,
2024-05-15 21:20:45 +00:00
});
final String contractAddress;
2023-04-03 22:38:48 +00:00
final double size;
@override
ConsumerState<EthTokenIcon> createState() => _EthTokenIconState();
}
class _EthTokenIconState extends ConsumerState<EthTokenIcon> {
late final String? imageUrl;
@override
void initState() {
imageUrl = ExchangeDataLoadingService.instance.isar.currencies
.where()
.filter()
.tokenContractEqualTo(widget.contractAddress, caseSensitive: false)
.findFirstSync()
?.image;
super.initState();
}
@override
Widget build(BuildContext context) {
if (imageUrl == null || imageUrl!.isEmpty) {
return SvgPicture.asset(
2024-05-15 21:20:45 +00:00
ref.watch(coinIconProvider(Ethereum(CryptoCurrencyNetwork.main))),
2023-04-03 22:38:48 +00:00
width: widget.size,
height: widget.size,
);
} else {
return SvgPicture.network(
imageUrl!,
2023-04-03 22:38:48 +00:00
width: widget.size,
height: widget.size,
);
}
}
}