[SOLVED] Copy method not holding state


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({

    FondoFormState copy, {
    List<TransferAccountDetails>? transferAccountDetails,
  }) : transferAccountDetails = transferAccountDetails ?? copy.transferAccountDetails;

  final List<TransferAccountDetails>? transferAccountDetails;

  List<Object?> get props => <Object?>[

  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) {
      FondoFormState.copy(state, transferAccountDetails: event.transferAccountDetails);
      // 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!


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.

people found this article helpful. What about you?