| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 3 | import 'package:cake_wallet/generated/i18n.dart'; |
| 4 | import 'package:cake_wallet/routes.dart'; |
| 5 | import 'package:cake_wallet/src/screens/dashboard/widgets/nft_tile_widget.dart'; |
| 6 | import 'package:cake_wallet/src/screens/dashboard/widgets/solana_nft_tile_widget.dart'; |
| 7 | import 'package:cake_wallet/src/widgets/primary_button.dart'; |
| 8 | import 'package:cake_wallet/view_model/dashboard/nft_view_model.dart'; |
| 9 | import 'package:cw_core/wallet_type.dart'; |
| 10 | |
| 11 | class NFTListingPage extends StatefulWidget { |
| 12 | final NFTViewModel nftViewModel; |
| 13 | |
| 14 | const NFTListingPage({super.key, required this.nftViewModel}); |
| 15 | |
| 16 | @override |
| 17 | State<NFTListingPage> createState() => _NFTListingPageState(); |
| 18 | } |
| 19 | |
| 20 | class _NFTListingPageState extends State<NFTListingPage> { |
| 21 | @override |
| 22 | void initState() { |
| 23 | super.initState(); |
| 24 | |
| 25 | fetchNFTsForWallet(); |
| 26 | } |
| 27 | |
| 28 | Future<void> fetchNFTsForWallet() async { |
| 29 | await widget.nftViewModel.getNFTAssetByWallet(); |
| 30 | } |
| 31 | |
| 32 | @override |
| 33 | Widget build(BuildContext context) { |
| 34 | return SliverToBoxAdapter( |
| 35 | child: Observer( |
| 36 | builder: (context) { |
| 37 | return Column( |
| 38 | children: [ |
| 39 | const SizedBox(height: 16), |
| 40 | Padding( |
| 41 | padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16), |
| 42 | child: PrimaryButton( |
| 43 | text: S.current.import, |
| 44 | color: Theme.of(context).colorScheme.surfaceContainer, |
| 45 | textColor: Theme.of(context).colorScheme.onSecondaryContainer, |
| 46 | onPressed: () => Navigator.pushNamed( |
| 47 | context, |
| 48 | Routes.importNFTPage, |
| 49 | arguments: widget.nftViewModel, |
| 50 | ), |
| 51 | ), |
| 52 | ), |
| 53 | if (widget.nftViewModel.isLoading) |
| 54 | Center( |
| 55 | child: CircularProgressIndicator( |
| 56 | backgroundColor: Theme.of(context).colorScheme.surfaceContainerHighest, |
| 57 | valueColor: AlwaysStoppedAnimation<Color>( |
| 58 | Theme.of(context).colorScheme.primary, |
| 59 | ), |
| 60 | ), |
| 61 | ) |
| 62 | else |
| 63 | NFTListWidget(nftViewModel: widget.nftViewModel) |
| 64 | ], |
| 65 | ); |
| 66 | }, |
| 67 | ), |
| 68 | ); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | class NFTListWidget extends StatelessWidget { |
| 73 | const NFTListWidget({required this.nftViewModel, super.key}); |
| 74 | |
| 75 | final NFTViewModel nftViewModel; |
| 76 | |
| 77 | @override |
| 78 | Widget build(BuildContext context) { |
| 79 | return Observer( |
| 80 | builder: (context) { |
| 81 | final isSolana = nftViewModel.appStore.wallet!.type == WalletType.solana; |
| 82 | |
| 83 | final emptyMessage = Center( |
| 84 | child: Text( |
| 85 | S.current.noNFTYet, |
| 86 | textAlign: TextAlign.center, |
| 87 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 88 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 89 | ), |
| 90 | ), |
| 91 | ); |
| 92 | |
| 93 | if (isSolana) { |
| 94 | if (nftViewModel.solanaNftAssetModels.isEmpty) return emptyMessage; |
| 95 | |
| 96 | return Padding( |
| 97 | padding: EdgeInsets.only(bottom: 64), |
| 98 | child: ListView.separated( |
| 99 | shrinkWrap: true, |
| 100 | physics: NeverScrollableScrollPhysics(), |
| 101 | padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 16), |
| 102 | separatorBuilder: (context, index) => const SizedBox(height: 8), |
| 103 | itemCount: nftViewModel.solanaNftAssetModels.length, |
| 104 | itemBuilder: (context, index) { |
| 105 | final nftAsset = nftViewModel.solanaNftAssetModels[index]; |
| 106 | return SolanaNFTTileWidget(nftAsset: nftAsset); |
| 107 | }, |
| 108 | ), |
| 109 | ); |
| 110 | } else { |
| 111 | if (nftViewModel.nftAssetByWalletModels.isEmpty) return emptyMessage; |
| 112 | |
| 113 | return Padding( |
| 114 | padding: EdgeInsets.only(bottom: 64), |
| 115 | child: ListView.separated( |
| 116 | shrinkWrap: true, |
| 117 | physics: NeverScrollableScrollPhysics(), |
| 118 | padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 16), |
| 119 | separatorBuilder: (context, index) => const SizedBox(height: 8), |
| 120 | itemCount: nftViewModel.nftAssetByWalletModels.length, |
| 121 | itemBuilder: (context, index) { |
| 122 | final nftAsset = nftViewModel.nftAssetByWalletModels[index]; |
| 123 | return NFTTileWidget(nftAsset: nftAsset); |
| 124 | }, |
| 125 | ), |
| 126 | ); |
| 127 | } |
| 128 | }, |
| 129 | ); |
| 130 | } |
| 131 | } |