title: Making a dropdown menu in Flutter with a Map
body: <p>so i'm wanting to create an object in flutter that takes a <code>Map&lt;String, int&gt;</code> as a list of values, where the <code>String</code> is what is displayed in the menu, and the <code>int</code> is stored inside the class for later usage after an item is selected.</p>
  
  <p>i am unsure how to do this. the part involving returning the <code>int</code> value eludes me.</p>
  
  <p>the map structure is written like this:</p>
  
  <pre><code>  final Map&lt;String, int&gt; discBasis = {
      'Age': 1,
      'Ancestry': 2,
      'Color': 3,
      'Disability': 4,
      'Race': 5,
      'Religion': 6,
      'Sex': 7,
      'Familial Status': 8,
      'National Origin': 9
    };
  </code></pre>
  
  <p>&amp; the class which i am currently using:</p>
  
  <pre><code>final double formMarginHoriz = 10.0;
  final double formMarginVert = 5.0;
  
  class DropDownFromMap extends StatefulWidget {
    Map&lt;String, int&gt; kv;
    DropDownFromMap(this.kv);
  
    @override
    DropDownFromMapState createState() =&gt; new DropDownFromMapState(kv);
  }
  
  class DropDownFromMapState extends State&lt;DropDownFromMap&gt; {
    Map&lt;String, int&gt; kv;
    DropDownFromMapState(this.kv);
  
    int selectedVal;
  
    @override
    Widget build(BuildContext context) {
      return new Container(
          margin: EdgeInsets.only(
              top: formMarginVert,
              bottom: formMarginVert,
              left: formMarginVert,
              right: formMarginHoriz),
          child: new DropdownButton&lt;int&gt;(
            hint: new Text("Select an option"),
            value: selectedVal,
            onChanged: (String newVal) {
              setState(() {
                selectedVal = kv[newVal];
              });
            },
            items: kv.map((String k, _) {
              return new DropdownMenuItem&lt;String&gt;(
                value: k,
                child: new Text(k),
              );
            }).toList(),
          ));
    }
  }
  </code></pre>
  
  <p>and it is instantiated like this (this is probably wrong):</p>
  
  <pre><code>  @override
    Widget build(BuildContext context) {
      return new Material(
          color: Colors.blueAccent,
          child: new Container(
              child: new Form(
                  key: _formKey,
                  child: new Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: &lt;Widget&gt;[
                      new DropDownFromMap(data.offenderType),
  ...
  </code></pre>
  
  <p>more context can be found at the github project: <a href="https://github.com/chscodeforchange/icrc-app" rel="noreferrer">https://github.com/chscodeforchange/icrc-app</a> in the relevant files: <code>dropdown.dart</code>, <code>off_page_one.dart</code>, &amp; <code>form_data.dart</code>.</p>
  
  <p>thank you in advance!</p>