The method 'bloc' isn't defined for the type 'BuildContext' The method 'bloc' isn't defined for the type 'BuildContext' flutter flutter

The method 'bloc' isn't defined for the type 'BuildContext'


After v6.1.0, both context.bloc and context.repository are deprecated in favor of context.read and context.watch. checkout the migration guide for more information.


I think that the below code that you used means that will use bloc from the parent widget defined with BlocProvider. But because it seems that you have a bloc instance in this widget you just use that instance.

// with extensionscontext.bloc<BlocA>();// without extensionsBlocProvider.of<BlocA>(context)

Because you used movieBloc at the MovieSuccessState state,I think you can just refer isFetching and add method using movieBloc instead of context.bloc<MovieBloc>().

return GridView.builder(                  controller: _scrollController                    ..addListener(() {                      if (_scrollController.offset ==                          _scrollController.position.maxScrollExtent) {                        //context.bloc<MovieBloc>()                        //  ..isFetching = true                        //  ..add(Fetch());                        movieBloc.isFetching = true;                        movieBloc.add(Fetch());                      }                    }),