mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
2877cc160c
* 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>
57 lines
1.4 KiB
Dart
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!;
|
|
}
|
|
}
|
|
}
|