Copy method not holding state

Viewed 22

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!

1 Answers

Calling emit on the state updates the state

Related