title: Flutter simple implementation to handle click event with Bloc work once
body: <p>I just learn about how can i use <code>Bloc</code> in flutter applications and my simple app i have some separated view class as <code>App</code> and <code>MainPage</code> and i implemented simple <code>Bloc</code> pattern to handle click event on some widgets such as button </p>
  
  <p>after running application my implemented bloc pattern only work once and show message in console and after click again that don't work to show message</p>
  
  <p>my <code>main.dart</code> class</p>
  
  <pre><code>void main() {
    runApp(MaterialApp(
      debugShowCheckedModeBanner: false,
      title: Strings.appName,
      theme: ThemeData(
        primarySwatch: Colors.indigo,
      ),
      home: App(),
    ));
  }
  
  class App extends StatefulWidget {
    final HomeBloc homeBloc = HomeBloc();
  
    @override
    State&lt;App&gt; createState() =&gt; MainPage();
  }
  </code></pre>
  
  <p><code>MainPage</code> class:</p>
  
  <pre><code>class MainPage extends State&lt;App&gt; {
    @override
    void initState() {
      super.initState();
    }
  
    HomeBloc get _homeBloc =&gt; widget.homeBloc;
  
    @override
    Widget build(BuildContext context) {
  
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: Strings.appName,
        theme: ThemeData(
          primarySwatch: Colors.indigo,
        ),
        home: BlocBuilder&lt;HomeEvent,HomeState&gt;(
            bloc: _homeBloc,
            builder: (BuildContext context, HomeState state) {
              if (state is HandleDrawerMenuClick) {
                _onWidgetDidBuild(() {
                  print("clicked on drawer menu");
                });
              }
  
              return Scaffold(
                body: Center(
                  child: RaisedButton(
                    child: Text('ddddddddd'),
                    onPressed: () {
                      _homeBloc.dispatch(OnDrawerMenuClicked());
                    },
                  ),
                ),
              );
            }),
      );
    }
  
    @override
    void dispose() {
      _homeBloc.dispose();
      super.dispose();
    }
  
    void _onWidgetDidBuild(Function callback) {
      WidgetsBinding.instance.addPostFrameCallback((_) {
        callback();
      });
    }
  }
  </code></pre>
  
  <p><code>HomeBloc</code> class:</p>
  
  <pre><code>class HomeBloc extends Bloc&lt;HomeEvent, HomeState&gt; {
    @override
    HomeState get initialState =&gt; HomeState();
  
    @override
    Stream&lt;HomeState&gt; mapEventToState(HomeEvent event) async* {
      if (event is OnDrawerMenuClicked) {
        yield HandleDrawerMenuClick();
      }
    }
  }
  </code></pre>
  
  <p><code>HomeEvent</code> class:</p>
  
  <pre><code>class HomeEvent extends Equatable {
    HomeEvent([List props = const []]) : super(props);
  }
  
  class OnDrawerMenuClicked extends HomeEvent {
    OnDrawerMenuClicked() : super([]);
  
    @override
    String toString() =&gt; 'OnDrawerMenuClicked clicked';
  }
  </code></pre>
  
  <p><code>HomeState</code> class:</p>
  
  <pre><code>class HomeState extends Equatable{
    HomeState([List props = const[]]):super(props);
  }
  
  class HandleDrawerMenuClick extends HomeState{
    @override
    String toString()=&gt;'HandleDrawerMenuClick';
  }
  </code></pre>
  
  <p>i think problem is on <code>HandleDrawerMenuClick</code> class because when i debug application, debug can go into <code>if</code> statement on this line:</p>
  
  <pre><code>if (event is OnDrawerMenuClicked) {
    yield HandleDrawerMenuClick();
  } 
  </code></pre>
  
  <p>and i think twice click on button couldn't trigger <code>yield HandleDrawerMenuClick();</code></p>