stack_wallet/lib/widgets/icon_widgets/eth_token_icon.dart

54 lines
1.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:isar/isar.dart';
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
class EthTokenIcon extends StatefulWidget {
const EthTokenIcon({
Key? key,
required this.contractAddress,
2023-04-03 22:38:48 +00:00
this.size = 22,
}) : super(key: key);
final String contractAddress;
2023-04-03 22:38:48 +00:00
final double size;
@override
State<EthTokenIcon> createState() => _EthTokenIconState();
}
class _EthTokenIconState extends State<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(
Assets.svg.iconFor(coin: Coin.ethereum),
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,
);
}
}
}