title: Update a widget from another one with Cubit Bloc
body: <p>I have two widgets on a screen a Loading Widget and a button widget I want to change the state of the loading widget every time I tap on the button.</p>
  <p>loading widget</p>
  <pre><code>class LoadingWidget extends StatelessWidget {
    const LoadingWidget({
      Key? key,
    }) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return BlocBuilder&lt;LoadingCubit, bool&gt;(
          bloc: BlocProvider.of&lt;LoadingCubit&gt;(context),
          builder: (context, loadingState) {
            return Center(
              child: Visibility(
                  visible: BlocProvider.of&lt;LoadingCubit&gt;(context).state,
                  child: const CircularProgressIndicator(
                    backgroundColor: Color(0xFF2C2C2C),
                  )),
            );
          });
    }
  }
  </code></pre>
  <p>loading cubit</p>
  <pre><code>class LoadingCubit extends Cubit&lt;bool&gt; {
    LoadingCubit() : super(true);
  
    toggleLoading() {
      emit(!state);
    }
  }
  </code></pre>
  <p>loading button</p>
  <pre><code>class AutoLoginButton extends StatelessWidget {
    const AutoLoginButton({
      Key? key,
    }) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return BlocBuilder&lt;AutoLoginCubit, bool&gt;(
        bloc: BlocProvider.of&lt;AutoLoginCubit&gt;(context),
        builder: (context, autoLoginState) =&gt; InkWell(
          child: Row(
            children: [
              Icon(
                autoLoginState == false
                    ? Icons.check_box_outline_blank
                    : Icons.check_box,
              ),
            ],
          ),
          onTap: () {
            BlocProvider.of&lt;AutoLoginCubit&gt;(context).toggleAutoLogin();
          },
        ),
      );
    }
  }
  </code></pre>
  <p>button cubit</p>
  <pre><code>class AutoLoginCubit extends Cubit&lt;bool&gt; {
    AutoLoginCubit() : super(false){
      initState().then((value) =&gt; emit(value));
    }
  
    void toggleAutoLogin() async {
      if (state == false) {
        emit(true);
      } else {
        emit(false);
      }
      AutoLoginService().setAutoLoginState(state: state);
    }
  
    Future&lt;bool&gt; initState() async{
      return await AutoLoginService().getAutoLoginState();
    }
  }
  </code></pre>
  <p>the page</p>
  <pre><code>Row(
   children:[
     BlocProvider(
         create: (context) =&gt; AutoLoginCubit(),
         child: const AutoLoginButton(),
         ),
     BlocProvider(
                create: (BuildContext context) =&gt; LoadingCubit(),
                child: const LoadingWidget()),
       ]
         )
  </code></pre>