dev
dart 93 lines 2.49 KB
Raw
1 class WalletNFTsResponseModel {
2 final int? page;
3 final int? pageSize;
4
5 final List<NFTAssetModel>? result;
6 final String? status;
7
8 WalletNFTsResponseModel({this.page, this.pageSize, this.result, this.status});
9
10 factory WalletNFTsResponseModel.fromJson(Map<String, dynamic> json) {
11 return WalletNFTsResponseModel(
12 page: json['page'] as int?,
13 pageSize: json['page_size'] as int?,
14 result: (json['result'] as List?)
15 ?.map((x) => NFTAssetModel.fromJson(x as Map<String, dynamic>))
16 .toList(),
17 status: json['status'] as String?,
18 );
19 }
20 }
21
22 class NFTAssetModel {
23 final String? tokenAddress;
24 final String? tokenId;
25 final String? contractType;
26 final String? name;
27 final String? symbol;
28 NormalizedMetadata? normalizedMetadata;
29
30 NFTAssetModel(
31 {this.tokenAddress,
32 this.tokenId,
33 this.contractType,
34 this.name,
35 this.symbol,
36 this.normalizedMetadata});
37
38 factory NFTAssetModel.fromJson(Map<String, dynamic> json) {
39 return NFTAssetModel(
40 tokenAddress: json['token_address'] as String?,
41 tokenId: json['token_id'] as String?,
42 contractType: json['contract_type'] as String?,
43 name: json['name'] as String?,
44 symbol: json['symbol'] as String?,
45 normalizedMetadata: json['normalized_metadata'] != null
46 ? new NormalizedMetadata.fromJson(json['normalized_metadata'] as Map<String, dynamic>)
47 : null,
48 );
49 }
50 }
51
52 class NormalizedMetadata {
53 final String? name;
54 final String? description;
55 final String? image;
56 NormalizedMetadata({
57 this.name,
58 this.description,
59 this.image,
60 });
61
62 factory NormalizedMetadata.fromJson(Map<String, dynamic> json) {
63 return NormalizedMetadata(
64 name: json['name'] as String?,
65 description: json['description'] as String?,
66 image: json['image'] as String?,
67 );
68 }
69
70 String? get imageUrl {
71 if (image == null) return image;
72
73 if (image!.contains('ipfs.io')) return image;
74
75 if (!image!.contains('ipfs')) return image;
76
77 // IPFS public gateway provided by Cloudflare is https://cloudflare-ipfs.com/ipfs/
78 //
79 // Here is an example of an ipfs image link:
80 //
81 // [ipfs://bafkreia2i2ctfexpovgzfff66wqhbmwwpvqjvozan7ioifzcnq76jharwu]
82
83 //https://ipfs.io/ipfs/QmTRcRXo6cXByjHYHTVxGpag6vpocrG3rxjPC9PxKAArR9/1620.png
84
85 const String ipfsPublicGateway = 'https://cloudflare-ipfs.com/ipfs/';
86
87 final ipfsPath = image?.split('//')[1];
88
89 final imageLink = '$ipfsPublicGateway$ipfsPath';
90
91 return imageLink;
92 }
93 }