Bloc: BlocConsumer Cubit

Created on 13 Aug 2020  路  6Comments  路  Source: felangel/bloc

Create to 2 types of state update functions. First one update blocListener state second blocBuilder state

question

Most helpful comment

You're returning return body(context, state); even for OnSuccess and OnError states but Widget body(BuildContext context, OpenDepositLoaded openDepositLoadedState) takes state of type OpenDepositLoaded which is not an OnSuccess or OnError.

You should rather use an enum say enum Status { success, error } that you can incorporate in the existing states that might overlap with your getDeposit call.

All 6 comments

Hi @II11II 馃憢

  • Would you mind giving more context around your suggestion ?
  • What exactly are you trying to achive that you haven't been able to achieve with the current implementation of flutter bloc ?
  • Could you give an example of how would this look like ?

F.i i have screen there 2 widgets(textfield and button) which depending on state ( loading, loaded, error). Im building 2 widgets in blockbuilder depending data that im receiving from rest api. After successfully building widgets, im sending data(in textfield) to api by button and i need to show pop up in bloclistener . So im crearing extra 2 states (onSuccess, onError). Having sent request by button i m showing popup however i have red death screen in bacground. Bloc consumer updates the BlocBuilder and bloclisterlner state by emit(). I think it would be good choice if there would be two separate update state functions, first for bloclistener state update function and second for BlocBuilder state update function

@II11II can you please provide a link to a sample app which illustrates the problem you're facing? Thanks 馃檹

You're returning return body(context, state); even for OnSuccess and OnError states but Widget body(BuildContext context, OpenDepositLoaded openDepositLoadedState) takes state of type OpenDepositLoaded which is not an OnSuccess or OnError.

You should rather use an enum say enum Status { success, error } that you can incorporate in the existing states that might overlap with your getDeposit call.

Yeap, I had idea to use enum but I cannot pass the response from api I think.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clicksocial picture clicksocial  路  3Comments

frankrod picture frankrod  路  3Comments

nerder picture nerder  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments