1

I have been working with Blocs and I always navigate in the same way:

Navigator.of(context).push(MaterialPageRoute(builder: (_) {
  return BlocProvider(
    create: (context) => MovieListBloc(),
    child: MovieListView(),
   );
}))

And now, I'm using a Cubit in a similar way, but getting the error on navigate about "Could not find the correct Provider above BlocBuilder.

Navigator.of(context).push(MaterialPageRoute(builder: (_) {
  return BlocProvider(
    create: (context) => MovieListCubit(),
    child: MovieListView(),
   );
}))

Am I missing something here, why can't they be used interchangeably?

I swapped the Bloc for a Cubit, and now I can't navigate.

spikeball
  • 11
  • 1
  • Please provide more details. Does the error include a stack trace? What does your code look like where the error actually occurs? Probably where you use BlocBuilder. – John Weidner Aug 06 '23 at 18:40

1 Answers1

0

i dont't know is it the good wah or no, but instead use BlocProvider() to push cubit with context, you can use BlocProvider.value(). On other page, wrap the widget with BlocBuilder to use the service in the Bloc/CUbit Class