title: Dart / flutter: DropdownButton causes exception when value is changed
body: <p>I have written a pretty extensive form using <code>DropdownButton</code> and <code>TextField</code> widgets. The concept is that I have a <code>StatefulWidget</code>, where the class of <code>State&lt;StatefulWidget&gt;</code> contains 2 methods that return the widget I want to build. This way I can easily access and use the entered data and pass it along a function to compose an e-mail out of them.</p>
  
  <p>However, when I select an item from the options, the framework throws an exception during the rebuild. I put in some log functions, and it shows that the <code>setState()</code> method successfully saves the value to <code>selectedValue</code> variable.</p>
  
  <pre><code>Widget buildMultiChoiceInputRow(var label, List&lt;String&gt; values) {
      final List&lt;String&gt; options = values.toList();
      selection = options.first;
  
      final dropDownMenuOptions = options.map((String value) {
        return new DropdownMenuItem&lt;String&gt;(
          value: value,
          child: new Text(value),
        );
      }).toList();
  
      return new Column(
        children: &lt;Widget&gt;[
          new Row(
            children: &lt;Widget&gt;[
              new Expanded(
                child: new Container(
                    padding:
                        const EdgeInsets.only(left: 5.0, top: 2.0, right: 5.0),
                    child: new Text(label, style: commonInfoCardInfoTextBlack16Bold)),
              ),
            ],
          ),
          new Row(
            children: &lt;Widget&gt;[
              new Expanded(
                child: new Container(
                  padding: const EdgeInsets.only(left: 5.0, right: 5.0),
                  child: new DropdownButton(
                  value: selectedValue,
                  items: dropDownMenuOptions,
                  onChanged: (selection) {
                    setState(() {
                      selectedValue = selection;
                      switch (label) {
                        case labelVirtualAdoption:
                          tempAdoptionType =
                              composeMultiChoiceAnswer(label, selection);
                              print(selection);
                              print(selectedValue);
                          break;
                            case labelAskedAboutSpecies:
                              tempAskedAboutSpecies =
                                  composeMultiChoiceAnswer(label, selection);
                              break;
                            case labelHouseOrFlat:
                              tempHouseOrFlat =
                                  composeMultiChoiceAnswer(label, selection);
                              break;
                              ....
                            default:
                              break;
                          }
                        });
                      }),
                ),
              )
            ],
          ),
          new Divider(color: Colors.transparent)
        ],
      );
    }
  </code></pre>
  
  <p>Here is the exception:</p>
  
  <pre><code>I/flutter (20998): The following assertion was thrown building AdoptionInput(dirty, state: AdoptionInputState#3cc80):
  I/flutter (20998): 'package:flutter/src/material/dropdown.dart': Failed assertion: line 481 pos 15: 'value == null ||
  I/flutter (20998): items.where((DropdownMenuItem&lt;T&gt; item) =&gt; item.value == value).length == 1': is not true.
  </code></pre>
  
  <p>And here is the stack, showing that the exception is thrown during the rebuild:</p>
  
  <pre><code>I/flutter (20998): #2      new DropdownButton (package:flutter/src/material/dropdown.dart)
  I/flutter (20998): #3      AdoptionInputState.buildMultiChoiceInputRow (package:osszefogasaszanhuzokert/adoptionPageUtilities.dart:443:28)
  I/flutter (20998): #4      AdoptionInputState.build (package:osszefogasaszanhuzokert/adoptionPageUtilities.dart:639:11)
  I/flutter (20998): #5      StatefulElement.build (package:flutter/src/widgets/framework.dart:3730:27)
  I/flutter (20998): #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3642:15)
  I/flutter (20998): #7      Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5)
  I/flutter (20998): #8      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2242:33)
  </code></pre>
  
  <p>The problem seems really similar to <a href="https://github.com/flutter/flutter/issues/6352" rel="noreferrer">a former bug in flutter</a>, but if I try to initialize the <code>selection</code> and <code>selectedValue</code> in <code>initState()</code>, the same exception will be thrown right as the form is built for the first time.</p>
  
  <p>What am I missing here?</p>