cake_wallet/lib/src/widgets/cake_image_widget.dart
Adegoke David 2877cc160c
CW-608-Fetch-And-Save-Icons-Of-ERC20-And-SPL-Tokens-When-Adding-Them (#1365)
* feat: Fetch and save icons of SPL tokens when adding them

* feat: Implement fetch and save icons for ERC20 tokens when adding them

* fix: Add moralisApiKey to evm secrets

* Add check to ensure decimals cannot be zero

* - Fallback to adding erc20 token from web3dart
- Wrap fetching spl token icon in a try/catch block

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-04-09 00:53:14 +02:00

57 lines
1.4 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class CakeImageWidget extends StatelessWidget {
CakeImageWidget({
required this.imageUrl,
Widget? displayOnError,
this.height,
this.width,
}) : _displayOnError = displayOnError ?? Icon(Icons.error);
final String? imageUrl;
final double? height;
final double? width;
final Widget? _displayOnError;
@override
Widget build(BuildContext context) {
try {
if (imageUrl == null || imageUrl!.isEmpty) return _displayOnError!;
if (imageUrl!.contains('assets/images')) {
return Image.asset(
imageUrl!,
height: height,
width: width,
);
}
if (imageUrl!.contains('.svg')) {
return SvgPicture.network(
imageUrl!,
height: height,
width: width,
);
}
return Image.network(
imageUrl!,
fit: BoxFit.cover,
height: height,
width: width,
loadingBuilder: (BuildContext _, Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) {
return child;
} else {
return CupertinoActivityIndicator(animating: true);
}
},
errorBuilder: (_, __, ___) => Icon(Icons.error),
);
} catch (_) {
return _displayOnError!;
}
}
}