Bloc: Yield no longer rebuilds after an await

Created on 17 Oct 2019  路  4Comments  路  Source: felangel/bloc

Hi,
Here is my states:
abstract class RegistrationFormState extends Equatable {

}

class InitialRegistrationFormState extends RegistrationFormState {
@override
List get props => null;
}
class VerificationLoading extends RegistrationFormState{
@override

List get props => null;

}
class VerificationResult extends RegistrationFormState{
Prisoner prisonerDetails;
VerificationResult(this.prisonerDetails);
@override
List get props => [prisonerDetails];

}

My Bloc:
if(event is VerifyIDNumber){
print("Verifying id number: ${event.idNumber} of type ${event.idType}");
//state.currentStep=1;
yield VerificationLoading();
await Future.delayed(Duration(seconds: 2));
print("Future finished");
yield VerificationResult(Prisoner());
}

the line yield VerificationResult never causes layout to be rebuilt. is there something am doing wrong? Kindly assist.

question

Most helpful comment

Hi,
Turns out down the widget tree i was calling bloc.close(); on a dispose method. Turns out we need to close on the same widget that created it only.
Thanks sir.

All 4 comments

Hi @kechkibet 馃憢
Thanks for opening an issue!

Can you please try updating your props getters to return an empty list of props like

@override
List get props => [];

For InitialRegistrationFormState and VerificationLoading? Thanks 馃憤

Hi,
Thanks for the quick response here is my state now:

class InitialRegistrationFormState extends RegistrationFormState {
@override
List get props => [];
}
class VerificationLoading extends RegistrationFormState{
@override

List get props => [];

}
class VerificationResult extends RegistrationFormState{
Prisoner prisonerDetails;
VerificationResult(this.prisonerDetails);
@override
// TODO: implement props
List get props => [prisonerDetails];

}

Here is the log:
I/flutter (23478): Verifying id number: 12312312 of type ID
I/flutter (23478): Verification Loading
I/flutter (23478): Future finished

As you can see the future finishes but the yield doesnt get to ui. Still same issue.

@kechkibet can you provide a link to a sample app which illustrates the issue? Thanks!

Hi,
Turns out down the widget tree i was calling bloc.close(); on a dispose method. Turns out we need to close on the same widget that created it only.
Thanks sir.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nerder picture nerder  路  3Comments

RobPFarley picture RobPFarley  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments

timtraversy picture timtraversy  路  3Comments

nhwilly picture nhwilly  路  3Comments