title: Best way to handle asyncronous events in flutter redux
body: <p>While starting to build an app using flutter and redux I came across the following issue: What's the best way to handle a network request or any asynchronous action?</p>
  
  <p>The context: 
  Make an asynchronous call to get a string from the server side (In my case just a Future.delayed) when the request finishes update the state and see the change in the view.</p>
  
  <p>First Approach:</p>
  
  <p>Create a middlewareClass that has an async call function that will wait for the asynchronous event to finish after it finishes call NextDispacther with a new action that will be treated in the reducers</p>
  
  <pre><code> class UserTypeMiddleware extends MiddlewareClass&lt;AppState&gt; {
  
        @override
        void call(Store&lt;AppState&gt; store, action, NextDispatcher next) async{
          if (action is GetTitleAction) {
            String title = await Future&lt;String&gt;.delayed(Duration(seconds: 2), () {
              return "This is a title ";
            });
            next(UpdateTitleAction(title));
          } else {
            next(action);
          }
        }
  
      }
  </code></pre>
  
  <p>Second approach: </p>
  
  <p>Create a typedMiddleware that does kind of the same thing but it dispatches the action via store.dispatch</p>
  
  <pre><code>TypedMiddleware&lt;AppState, GetTitleAction&gt; userTypeMiddleware() =&gt;
      TypedMiddleware&lt;AppState, GetTitleAction&gt;(_getTitle);
  
  Future _getTitle(Store&lt;AppState&gt; store, GetTitleAction action, NextDispatcher next) async {
    String title = await Future&lt;String&gt;.delayed(Duration(seconds: 2), () {
      return "Flow.me este o aplicatie care va permite sa inchiriati un scooter ";
    });
    store.dispatch(UpdateTitleAction(title));
    next(action);
  }
  </code></pre>
  
  <p>Third approach:</p>
  
  <p>Use redux_thunk</p>
  
  <pre><code>ThunkAction&lt;AppState&gt; updateTitleAction = (Store&lt;AppState&gt; store) async {
    String title = await Future&lt;String&gt;.delayed(Duration(seconds: 2), () {
      return "Flow.me este o aplicatie care va permite sa inchiriati un scooter ";
    });
  
    store.dispatch(UpdateTitleAction(title));
  };
  </code></pre>
  
  <p>From my point of view I would rather deal with the logic of handling server request in the middleware and not in an action - just for the sake of consistency - middlewares being at the same level as a reducer, for handling logic. </p>
  
  <p>Does it break the redux idea in any way if I am calling NextDispatcher in the middleware with a delay from the async request? Could this represent a problem? </p>