Created
December 9, 2022 15:53
-
-
Save ibrajix/d1a397b6cfca46859f79d98724bc1ca0 to your computer and use it in GitHub Desktop.
nft_bloc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NftBloc extends Bloc<NftEvent, ApiState> { | |
final NftRepository _nftRepository; | |
NftBloc(this._nftRepository) : super(ApiState.initial(const [], const [])) { | |
on<GetNftEvent>((event, emit) async { | |
emit(state.copyWith( | |
status: Status.loading | |
)); | |
try{ | |
final allNft = await _nftRepository.getAllNft(); | |
final topNft = List<TopNft>.from(allNft[0].map((i) => TopNft.fromJson(i))); | |
final trendingNft = List<TrendingNft>.from(allNft[1].map((i) => TrendingNft.fromJson(i))); | |
emit(state.copyWith( | |
status: Status.success, | |
topNft: topNft, | |
trendingNft: trendingNft | |
)); | |
}catch(e){ | |
emit(state.copyWith( | |
status: Status.error, | |
error: e.toString() | |
)); | |
debugPrint("error: $e"); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment