title: How to switch on Enum in Dart?
body: <p>I'm watching The Boring Flutter Development Show where in one of the episodes they're showing the implementation of Bloc.</p>
  
  <p>Now there's this chunk of code that I thought would be better replace with Switch statement, you know, in case there appears more cases in the future:</p>
  
  <pre class="lang-dart prettyprint-override"><code>_storiesTypeController.stream.listen((storiesType) {
         if (storiesType == StoriesType.newStories) {
           _getArticlesAndUpdate(_newIds);
         } else {
           _getArticlesAndUpdate(_topIds);
         }
       });
  </code></pre>
  
  <p>... so I tried to implement it but it gave me some error saying that </p>
  
  <blockquote>
    <p>Type 'Type' of the switch expression isn't assignable to the type 'Stories Type' of case expressions.</p>
  </blockquote>
  
  <p>So I came up with this workaround:</p>
  
  <pre class="lang-dart prettyprint-override"><code>final storyType = StoriesType.newStories;
  
  _storiesTypeController.stream.listen((storyType) {
      switch (storyType) {
        case StoriesType.newStories: {
          _getArticlesAndUpdate(_newIds);
        }
          break;
        case StoriesType.topStories: {
          _getArticlesAndUpdate(_topIds);
        }
          break;
        default: {
          print('default');
        }
      }
    });
  </code></pre>
  
  <p>... and everything works fine but I wonder if there's another way to switch Enum and why it says the value of local variable storyType isn't used, when I use it in this line:</p>
  
  <pre><code>_storiesTypeController.stream.listen((storyType)
  </code></pre>
  
  <p>and I switch over it?</p>