title: Sending data to other page with bloc cubit
body: <p>My problem is this. I created cubit for 2 different pages. When I am on the first page, I can fill the list inside the 2nd page and I can read it from the log. However, when I go to the second page, the list I filled in from the previous page is still empty.</p>
  <blockquote>
  <p>Main.dart</p>
  </blockquote>
  <pre><code>home:
            
            
             MultiBlocProvider(
              providers: [
                BlocProvider(create: (_) =&gt; HomeCubit(PhotoService())),
                
                BlocProvider(create: (_)=&gt; FavoritesCubit())//Gerekiyor,homeviewda içerisindeki methoda erişmem gerekiyor
              ],
              child: const HomeView())
  </code></pre>
  <blockquote>
  <p>HomeView.dart</p>
  </blockquote>
  <pre><code>where I run the function in favoritescubit and add it to the list
   onTap: () {
                          
  
                          BlocProvider.of&lt;FavoritesCubit&gt;(context).addFavorite(
                              context,
                              state.selectItem![index],
                              );
                          print(state.selectItem?[index].isSelected);
                          context.read&lt;FavoritesCubit&gt;().getAllFavorites();
  
                          // print(&quot;UI --- ${state.selectItem![index].isSelected}&quot;);
                          //  context.read&lt;FavoriteBloc&gt;().add(
                          //      AddFavorite(photoList, photoList.isSelected));
                          //  print(&quot; ispressed ${photoList.isSelected}&quot;);
                        },
  </code></pre>
  <blockquote>
  <p>FavoritesCubit.dart</p>
  </blockquote>
  <pre><code>class FavoritesCubit extends Cubit&lt;FavoritesState&gt; {
    FavoritesCubit() : super(const FavoritesState());
  
    final List&lt;PhotoModel&gt; favoriteList = &lt;PhotoModel&gt;[];
  
    Future&lt;void&gt; getAllFavorites() async {
      print(&quot;FavoriteList : ${favoriteList.length}&quot;);
      emit(state.copyWith(favoriteList: favoriteList));
    }
  
  
  
   
  
       Future&lt;void&gt; addFavorite(
          BuildContext context,
          PhotoModel photo,
        ) async {
          photo.isSelected = !photo.isSelected;
          if (favoriteList.contains(photo) == false) {
            favoriteList.add(photo);
            emit(state.copyWith(
                favoriteList: favoriteList, isFavorite: photo.isSelected));
            print(&quot;${state.favoriteList!.length}asdasd&quot;);
          } else if (favoriteList.contains(photo) == true) {
            favoriteList.remove(photo);
            emit(state.copyWith(
                favoriteList: favoriteList, isFavorite: photo.isSelected));
            print(&quot;${state.favoriteList!.length}asdasd&quot;);
          }
  </code></pre>
  <blockquote>
  <p>FavoriteView.dart</p>
  </blockquote>
  <pre><code>class FavoriteView extends StatefulWidget {
    const FavoriteView({Key? key}) : super(key: key);
  
    @override
    State&lt;FavoriteView&gt; createState() =&gt; _FavoriteViewState();
  }
  
  class _FavoriteViewState extends State&lt;FavoriteView&gt; {
    @override
    void initState() {
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return BlocProvider(
        create: (context) =&gt; FavoritesCubit()..getAllFavorites(),
        child: Scaffold(
          appBar: AppBar(
            title: const Text(&quot;Bloc Example&quot;),
          ),
          body: buildFavoriteList(context),
        ),
      );
    }
  }
  
  
  
  
  Widget buildFavoriteList(BuildContext context) {
   
    return BlocConsumer&lt;FavoritesCubit, FavoritesState&gt;(
      listener: (context, state) {
        // TODO: implement listener
      },
      builder: (context, state) {
        return ListView.builder(
            itemCount: state.favoriteList?.length,
            itemBuilder: (context, index) {
              return GestureDetector(
                onTap: (() {
                  // navigateToPostDetailPage(context, photos[index]);
                }),
                child: Padding(
                  padding: const EdgeInsets.all(10),
                  child: PhotoListTile(
                    isPressed: state.favoriteList![index].isSelected,
                    imageUrl: state.favoriteList![index].thumbnailUrl.toString(),
                    title: state.favoriteList![index].title.toString(),
                    url: state.favoriteList![index].url.toString(),
                    onTap: () {
                      // context.read&lt;HomeCubit&gt;().addFavorite(
                      //     context,
                      //     state.favoriteList![index],
                      //     state.favoriteList![index].isSelected);
                      // context
                      //     .read&lt;FavoriteBloc&gt;()
                      //     .add(RemoveFavorite(photos[index]));
                    },
                  ),
                ),
              );
            });
      },
    );
  </code></pre>