Issue
This Content is from Stack Overflow. Question asked by flutter
I’m using flutter_bloc. I have one class to hold state.
class FondoFormState extends Equatable {
const FondoFormState({
this.transferAccountDetails,
});
FondoFormState.copy(
FondoFormState copy, {
List<TransferAccountDetails>? transferAccountDetails,
}) : transferAccountDetails = transferAccountDetails ?? copy.transferAccountDetails;
final List<TransferAccountDetails>? transferAccountDetails;
@override
List<Object?> get props => <Object?>[
transferAccountDetails,
];
@override
bool get stringify => true;
}
I’m calling the event from the UI..
with context.read<FondoFormBloc>().add(AddAccountEvent(accounts));
My bloc is is receiving the event..(from the print statement)
However when I print the state I get null for transferAccountDetails
on< AddAccountEvent >((AddAccountEvent event, Emitter<FondoFormState> emit) {
print(event.transferAccountDetails);
FondoFormState.copy(state, transferAccountDetails: event.transferAccountDetails);
print(state);
// FondoFormState.copy(state, fondoAccounts: fondoAccounts);
});
The issue is probably with the copy
method in the state class. It’s not holding the state. Wonder can anyone notice my error!
Solution
Calling emit on the state updates the state
This Question was asked in StackOverflow by flutter and Answered by flutter It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.