title: how to access flutter bloc in the initState method?
body: <p>In the code shown below , the dispatch event is called from within the build method after getting the BuildContext object. What if I wish to do is to dispatch an event during processing at the start of the page within the initState method itself ? </p>
  
  <p>If I use didChangeDependencies method , then I am getting this error : 
  <code>BlocProvider.of() called with a context that does not contain a Bloc of type FileManagerBloc.</code> how to fix this? </p>
  
  <pre><code>  @override
    Widget build(BuildContext context) {
      return Scaffold(
          body: BlocProvider&lt;FileManagerBloc&gt;(
            builder: (context)=&gt;FileManagerBloc(),
            child: SafeArea(
        child: Container(
            child: Column(
              children: &lt;Widget&gt;[
                Container(color: Colors.blueGrey, child: TopMenuBar()),
                Expanded(
                  child: BlocBuilder&lt;FileManagerBloc,FileManagerState&gt;(
                    builder: (context , state){
                      return GridView.count(
                        scrollDirection: Axis.vertical,
                        physics: ScrollPhysics(),
                        crossAxisCount: 3,
                        crossAxisSpacing: 10,
                        children: getFilesListWidget(context , state),
                      );
                    },
                  ),
                )
              ],
            ),
        ),
      ),
          ));
    }
  
    @override
    void dispose() {
      super.dispose();
    }
  
    @override
    void didChangeDependencies() {
      logger.i('Did change dependency Called');
      final FileManagerBloc bloc = BlocProvider.of&lt;FileManagerBloc&gt;(context) ;
      Messenger.sendGetHomeDir()
          .then((path) async {
        final files = await Messenger.sendListDir(path);
          bloc.dispatch(SetCurrentWorkingDir(path)) ;
          bloc.dispatch(UpdateFileSystemCacheMapping(path , files)) ;
      });
    }
  </code></pre>