title: How to insert dropdownbutton value to databse mysql using flutter
body: <p>I'm new on flutter framework, i have some problem with dropdownbutton. How to save selected dropdownbutton to the mysql database</p>
  
  <p>This code is actually works to save to the mysqldb for textfield. But how to get selected dropdownbutton value </p>
  
  <pre><code>    class FormOrtuView extends StatefulWidget {
    @override
    _FormOrtuViewState createState() =&gt; _FormOrtuViewState();
  }
  
  class _FormOrtuViewState extends State&lt;FormOrtuView&gt; {
    String _dropdownValueAgm = 'Katolik';
  
    final _key = new GlobalKey&lt;FormState&gt;();
  </code></pre>
  
  <p>Insert to database code:</p>
  
  <pre><code>sumbit(String namaAyah,agamaAyah) async {
      var ayah = {
        "id_register": idReg,
        "nama_ayah": namaAyah,
        "agama_ayah": agamaAyah,
      };
      final response = await http.post(BaseUrl.ayah, body: {
        'id_register': ayah['id_register'],
        'nama_ayah': ayah['nama_ayah'],
        'agama_ayah': ayah['agama_ayah'],
      });
      print(response.statusCode);
      final data = jsonDecode(response.body);
      print(data);
    }
  </code></pre>
  
  <p>Code to show dropdownbutton value</p>
  
  <pre><code>DropdownButton&lt;String&gt; _buildDropdownButtonAgama() {
      return DropdownButton&lt;String&gt;(
        value: _dropdownValueAgm,
        onChanged: (String agamaAyah) {
          setState(() {
            _dropdownValueAgm = agamaAyah;
          });
        },
        items: &lt;String&gt;[
          'Katolik',
          'Kristen',
          'Islam',
          'Hindu',
          'Buddha',
          'Kong Hu Chu',
          'Kepercayaan'
        ].map&lt;DropdownMenuItem&lt;String&gt;&gt;((String value) {
          return DropdownMenuItem&lt;String&gt;(
            value: value,
            child: Text(value),
          );
        }).toList(),
      );
   }
  </code></pre>
  
  <p>Return code to display ui</p>
  
  <pre><code>List&lt;DemoItem&lt;dynamic&gt;&gt; _demoItems;
  @override
    void initState() {
      super.initState();
      getPref();
           return Form(
              key: _key,
              child: Builder(
                builder: (BuildContext context) {
                  return CollapsibleBody(
                    margin: const EdgeInsets.symmetric(horizontal: 16.0),
                    onSave: () {
                      Form.of(context).save();
                      close();
                      _sumbit(namaAyah, agamaAyah);
                    },
                    onCancel: () {
                      Form.of(context).reset();
                      close();
                    },
                    child: Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 16.0),
                      child: Column(
                        children: &lt;Widget&gt;[
                          TextFormField(
                            decoration: InputDecoration(
                              hintText: "ex. John john",
                              labelText: "Nama",
                            ),
                            onSaved: (e) =&gt; namaAyah = e,
                          ),
  </code></pre>
  
  <p>Dropdown button code</p>
  
  <pre><code>Container(
                            margin: EdgeInsets.only(bottom: 10.0),
                            decoration: ShapeDecoration(
                              shape: RoundedRectangleBorder(
                                  side:
                                      BorderSide(color: Colors.grey, width: 1.0),
                                  borderRadius: BorderRadius.circular(10.0)),
                            ),
                            width: 320.0,
                            child: DropdownButtonHideUnderline(
                              child: ButtonTheme(
                                alignedDropdown: true,
                                child: _buildDropdownButtonAgama(),
                              ),
                            ),
                          ),
                        ],
                    );
          },
        ),
  </code></pre>