title: Flutter combo box item in list view
body: <p>I'm trying to make a combobox and when I select an item, I want it to be added in a listview when a button is pressed.</p>
  <p>I tried multiple solutions, but none seems to work, as far as I did, I could make a input field and add the items manually, but I can't do it with a combobox  ( without letting the user write them manually ).</p>
  <p>Here is what I did:</p>
  <pre><code>
  
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  import 'package:searchable_dropdown/searchable_dropdown.dart';
  
  
  class LocationTab extends StatefulWidget {
    @override
    _LocationTabState createState() =&gt; _LocationTabState();
  }
  
  class _LocationTabState extends State&lt;LocationTab&gt; {
    List&lt;String&gt; mylist = List();
  
  
    List&lt;ParentCategoryComboBox&gt; _visibility =
        ParentCategoryComboBox.getParentCategory();
    List&lt;DropdownMenuItem&lt;ParentCategoryComboBox&gt;&gt; _dropdownMenuItems;
  
    List&lt;PlatformReachComboBox&gt; _platformReach =
        PlatformReachComboBox.getPlatformReach();
    List&lt;DropdownMenuItem&lt;PlatformReachComboBox&gt;&gt; _dropdownPlatformReach;
  
    PlatformReachComboBox _selectedPlatformReach;
  
    ParentCategoryComboBox _selectedVisibility;
  
    @override
    void initState() {
      _dropdownMenuItems = buildDropDownMenuItems(_visibility);
      _selectedVisibility = _dropdownMenuItems[0].value;
  
      _dropdownPlatformReach =
          buildDropdownMenuItemsPlatformReach(_platformReach);
      _selectedPlatformReach = _dropdownPlatformReach[0].value;
  
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return Container(
        padding: EdgeInsets.only(top: 10.0, left: 20.0, right: 20.0),
        child: SingleChildScrollView(
          physics: BouncingScrollPhysics(),
          scrollDirection: Axis.vertical,
          child: Column(
            children: &lt;Widget&gt;[
              SizedBox(
                height: 20,
              ),
              Column(
                children: [
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      &quot;Select visibility:&quot;,
                      style: TextStyle(
                        color: Colors.indigoAccent,
                        fontWeight: FontWeight.bold,
                        fontSize: 16,
                      ),
                    ),
                  ),
                ],
              ),
              DropdownButton(
                icon: Icon(
                  Icons.visibility,
                  color: Colors.black45,
                ),
                isExpanded: true,
                value: _selectedVisibility,
                items: _dropdownMenuItems,
                onChanged: (ParentCategoryComboBox selectedVisibility) {
                  setState(() {
                    _selectedVisibility = selectedVisibility;
                  });
                },
              ),
              SizedBox(
                height: 35,
              ),
              Container(
                padding: new EdgeInsets.symmetric(horizontal: 5.0),
                decoration: BoxDecoration(
                    border: Border.all(
                      width: 1,
                      color: Colors.grey,
                    ),
                    borderRadius: BorderRadius.circular((10))),
                child: Column(
                  children: &lt;Widget&gt;[
                    SizedBox(
                      height: 10,
                    ),
                    Align(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        &quot;Select platform reach:&quot;,
                        style: TextStyle(
                          color: Colors.indigoAccent,
                          fontWeight: FontWeight.bold,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Row(
                      children: &lt;Widget&gt;[
                        Expanded(
                          child: SearchableDropdown(
                            isExpanded: true,
                            value: _selectedPlatformReach,
                            items: _dropdownPlatformReach,
                            isCaseSensitiveSearch: false,
                            onChanged:
                                (PlatformReachComboBox selectedPlatformReach) {
                              setState(() {
                                _selectedPlatformReach = selectedPlatformReach;
                              });
                            },
                          ),
                          flex: 2,
                        ),
                        Expanded(
                          child: Container(
                            height: 50.0,
                            width: 80,
                            child: Material(
                              borderRadius: BorderRadius.circular(20.0),
                              shadowColor: Colors.blue,
                              color: Colors.deepPurpleAccent,
                              elevation: 0.0,
                              child: GestureDetector(
                                onTap: () {
                                  setState(() {
                                    mylist.add(_selectedPlatformReach.toString());
                                  });
                                },
                                child: Center(
                                  child: Text(
                                    'ADD',
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          ),
                          flex: 0,
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    Align(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        &quot;Added:&quot;,
                        style: TextStyle(
                          color: Colors.indigoAccent,
                          fontWeight: FontWeight.bold,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    ListView.builder(
                      padding: EdgeInsets.only(left: 10),
                      scrollDirection: Axis.vertical,
                      shrinkWrap: true,
                      itemCount: mylist.length,
                      itemBuilder: (BuildContext ctxt, int Index) {
                        return Text(
                            mylist[Index]
                        );
  
                      },
                    ),
  //                  ListView.builder(
  //                    padding: EdgeInsets.only(left: 10),
  //                    scrollDirection: Axis.vertical,
  //                    shrinkWrap: true,
  //                    itemCount: _platformReach.length,
  //                    itemBuilder: (BuildContext ctxt, int Index) {
  //                      return Text(
  //                        &quot;Galati&quot;
  //                      );
  ////                      return DropdownButton(
  ////                        value: _selectedPlatformReach.toString(),
  ////                        items: _dropdownPlatformReach,
  ////                        onChanged: (value) {
  ////                          _selectedPlatformReach = value;
  ////                          setState(() {});
  ////                        },
  ////                        hint: Text('Select drowdown'),
  ////                      );
  ////                                return new Text(_dropdownPlatformReach[Index].value);
  //                    },
  //                  ),
                  ],
                ),
              ),
            ],
          ),
        ),
      );
    }
  }
  
  </code></pre>
  <p>Mock data class:</p>
  <pre><code>import 'package:flutter/material.dart';
  
  class PlatformReachComboBox {
    String name;
    String hint;
  
    PlatformReachComboBox(this.name, this.hint);
  
    static List&lt;PlatformReachComboBox&gt; getPlatformReach() {
      return &lt;PlatformReachComboBox&gt;[
        PlatformReachComboBox('Jud Galati', '(RO, [Galati] County)'),
        PlatformReachComboBox('Jud Braila', '(RO, [Braila] County)'),
        PlatformReachComboBox('Jud Prahova', '(RO, [Ploiesti] County)'),
        PlatformReachComboBox('Jud Maramures', '(RO, [Baia Mare] County)'),
      ];
    }
  }
  
  List&lt;DropdownMenuItem&lt;PlatformReachComboBox&gt;&gt;
      buildDropdownMenuItemsPlatformReach(List platforms) {
    List&lt;DropdownMenuItem&lt;PlatformReachComboBox&gt;&gt; items = List();
    for (PlatformReachComboBox platform in platforms) {
      items.add(
        DropdownMenuItem(
          value: platform,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: &lt;Widget&gt;[
              Text(
                platform.name,
                style: TextStyle(fontWeight: FontWeight.bold),
                textAlign: TextAlign.start,
              ),
              Text(
                platform.hint,
                style:
                    TextStyle(fontWeight: FontWeight.normal, color: Colors.grey),
                textAlign: TextAlign.end,
              )
            ],
          ),
        ),
      );
    }
    return items;
  }
  </code></pre>
  <p>And this is where I encounter the problem, I don't know what to return in ListView for me pressing the button, and then the item to be added in there:</p>
  <pre><code>   ListView.builder(
                      padding: EdgeInsets.only(left: 10),
                      scrollDirection: Axis.vertical,
                      shrinkWrap: true,
                      itemCount: _platformReach.length,
                      itemBuilder: (BuildContext ctxt, int Index) {
                        return Text(
                          &quot;Galati&quot;
                        );
  
                      },
                    ),
  </code></pre>