0

it gives me this error:

Unhandled Exception: Bad state: Cannot add new events after calling close.

1 Answers1

2

Maybe I'm a bit late but my guess is that you used

BlocProvider<ExistingCubit>(
  create: (_) => ExistingCubit(),
)

to pass existing cubit to new page.

You should instead use

BlocProvider.value(
 value: context.read<ExistingCubit>()
)

As the docs say

BlocProvider.value Takes a [value] and a [child] which will have access to the [value] via BlocProvider.of(context). When BlocProvider.value is used, the [Bloc] or [Cubit] will not be automatically closed. As a result, BlocProvider.value should only be used for providing existing instances to new subtrees. A new [Bloc] or [Cubit] should not be created in BlocProvider.value. New instances should always be created using the default constructor within the [Create] function.

RandomSlav
  • 507
  • 3
  • 13