title: How can I create form modal with dropdown select in flutter
body: <p>I am new to flutter and this is my first application. I have been trying to create a form modal with dropdown select would receive its data from the server. but for now I am using the values in array I created but it not setting the value after I select an item. I tried to add a setState() but is showing error. Please can someone help me?</p>
  
  <p>Here is my code blow</p>
  
  <pre><code>import 'dart:async';
  import 'package:flutter/material.dart';
  import 'package:erg_app/ProfilePage.dart';
  
  void main() =&gt; runApp(
      MaterialApp(
        debugShowCheckedModeBanner: false,
        home: StockPage(),
      )
  );
  
  class StockPage extends StatelessWidget {
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Inventory Data',
        theme: ThemeData(
          primarySwatch: Colors.green,
        ),
        home: StockInventory(),
      );
    }
  }
  
  class StockInventory extends StatefulWidget {
  
    StockInventory({Key key}) : super(key: key); //Find out meaning
  
    @override
    _StockInventoryState createState() =&gt; _StockInventoryState();
  }
  
  
  class _StockInventoryState extends State&lt;StockInventory&gt; {
  
  
     List&lt;Products&gt; products;
    List&lt;Products&gt; selectedProducts;
    bool sort;
  
    @override
    void initState() {
      sort = false;
      selectedProducts = [];
      products = Products.getProducts();
      super.initState();
    }
  
    onSortColum(int columnIndex, bool ascending) {
      if (columnIndex == 0) {
        if (ascending) {
          products.sort((a, b) =&gt; a.name.compareTo(b.name));
        } else {
          products.sort((a, b) =&gt; b.name.compareTo(a.name));
        }
      }
    }
  
     @override
    Widget build(BuildContext context){
          return Scaffold(
            appBar: AppBar(
            title: new Center(child: new Text('Daily Stock Taking', textAlign: TextAlign.center)),
            automaticallyImplyLeading: false,
            iconTheme: IconThemeData(color: Colors.white),
            backgroundColor: Colors.green,),
  
            body: Container(
              child: ListView(
                children: &lt;Widget&gt;[
                  Container(
                    margin: const EdgeInsets.only(right: 20, top: 20),
                    child: Align(
                       alignment: Alignment.bottomRight,
                       child: RaisedButton(
                          padding: EdgeInsets.fromLTRB(14, 10, 14, 10),
                          color: Colors.green,
                          child: Text("Take Inventory", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14), ),
                          onPressed: () {
                            // Navigator.of(context).push(MaterialPageRoute(builder: (context) =&gt; ProfilePage()));
                            showSimpleCustomDialog(context);
                          },
                          shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(50),
  
                        ),
                        ),
                      ),
                    ),
  
                  Container(
                      padding: EdgeInsets.only(top: 30, bottom: 30),
                      child: DataTable(
                      sortAscending: sort,
                      sortColumnIndex: 0,
                      columns: [
                        DataColumn(
                          label: Text("S/No", style: TextStyle(fontSize: 16)),
                          numeric: false,
                        ),
                        DataColumn(
                            label: Text("Item", style: TextStyle(fontSize: 16)),
                            numeric: false,
                            onSort: (columnIndex, ascending) {
                              setState(() {
                                sort = !sort;
                              });
                              onSortColum(columnIndex, ascending);
                            }),
                        DataColumn(
                          label: Text("QtyInStock", style: TextStyle(fontSize: 16)),
                          numeric: false,
                        ),
                        DataColumn(
                          label: Text("Unit", style: TextStyle(fontSize: 16)),
                          numeric: false,
                        ),
                      ],
                      rows: products
                          .map(
                            (product) =&gt; DataRow(
                                selected: selectedProducts.contains(product),
                                cells: [
                                  DataCell(
                                    Text(product.count),
                                    onTap: () {
                                      print('Selected ${product.count}');
                                    },
                                  ),
                                  DataCell(
                                    Text(product.name),
                                    onTap: () {
                                      print('Selected ${product.name}');
                                    },
                                  ),
                                  DataCell(
                                    Text(product.itemqty),
                                    onTap: () {
                                      print('Selected ${product.itemqty}');
                                    },
                                  ),
                                  DataCell(
                                    Text(product.itemqty),
                                    onTap: () {
                                      print('Selected ${product.itemqty}');
                                    },
                                  ),
                                ]),
                          ).toList(),
                      ),          
                  ),
                  Container(
                      child: Center(
                        child: RaisedButton(
                          padding: EdgeInsets.fromLTRB(80, 10, 80, 10),
                          color: Colors.green,
                          child: Text("Post Inventory", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14), ),
                          onPressed: () {
                            Navigator.of(context).push(MaterialPageRoute(builder: (context) =&gt; ProfilePage()));
                          },
                          shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(50),
                        ),
                        ),
                      ),
                    ),
                ],
              ),
            ),
          );
    }
  }
  
  
  
  class Products {
    String count;
    String name;
    String measuringunit;
    String itemqty;
    Products({this.count, this.name, this.itemqty, this.measuringunit});
  
    static List&lt;Products&gt; getProducts() {
      return &lt;Products&gt;[
        Products(count:"1", name: "NPK Fertilizer", itemqty: "50", measuringunit: "bag",),
        Products(count:"2", name: "Urea Fertilizer", itemqty: "560", measuringunit: "bag",),
        Products(count:"3", name: "Spray", itemqty: "150", measuringunit: "bottles",),
      ];
    }
  
  
  }
  
  
  void showSimpleCustomDialog(BuildContext context) {
    String dropdownValue = 'SelectItem';
  
    // TextEditingController _controller = TextEditingController(text: dropdownValue);
  
      Dialog simpleDialog = Dialog(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(12.0),
        ),
        child: Container(
          height: 300.0,
          width: 300.0,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: &lt;Widget&gt;[
             Padding( 
                  padding: EdgeInsets.only(top:20, bottom: 20, left: 30, right: 10),
                  child: Row(
                  children: &lt;Widget&gt;[
                    Expanded(child: 
                      Text(
                        'Item',
                        style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, ),
                        ),
                    ),
                    Container(width: 2,),
                    Container(
  
                      child:DropdownButton&lt;String&gt;(
                        value: dropdownValue,
  
                         onChanged: (String newValue) {
                          // This set state is trowing an error
                          setState((){
                            dropdownValue = newValue;
                          });
                        },
  
                        items: &lt;String&gt;['Fertilizers', 'Bags', 'Spray', 'Equipments']
                        .map&lt;DropdownMenuItem&lt;String&gt;&gt;((String value) {
                          return DropdownMenuItem&lt;String&gt;(
                            value: value,
                            child: new Text(value),
                          );
                        })
                        .toList(),        
                      ),
  
                    ),
                  ],
                )),  
  
              Padding( 
                  padding: EdgeInsets.only(top:5, bottom: 5, left: 30, right: 10),
                  child: Row(
                  children: &lt;Widget&gt;[
                    Expanded(child: 
                      Text(
                        'Quantity',
                        style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, ),
                        ),
                    ),
                    Container(width: 2,),
                    Expanded(child: TextField(
                      keyboardType: TextInputType.number,
                      decoration: InputDecoration(
                          labelText: 'Quantity',
                          hintText: 'Enter Cost Quantity',
                          border:OutlineInputBorder(borderRadius: BorderRadius.circular(5.0))
                      ),
                    )),  
                  ],
                )),  
  
              Padding(
                padding: const EdgeInsets.only(left: 10, right: 10, top: 10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: &lt;Widget&gt;[
                    RaisedButton(
                      color: Colors.blue,
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                      child: Text(
                        'Add',
                        style: TextStyle(fontSize: 18.0, color: Colors.white),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    RaisedButton(
                      color: Colors.red,
                      onPressed: () {
                        Navigator.pop(context);
                        // Navigator.of(context).push(MaterialPageRoute(builder: (context) =&gt; StockPage()));
                      },
                      child: Text(
                        'Cancel!',
                        style: TextStyle(fontSize: 18.0, color: Colors.white),
                      ),
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
      );
      showDialog(context: context, builder: (BuildContext context) =&gt; simpleDialog);  
  
  
  }
  
  
  // Dropdown Menu Class below
  
  
  </code></pre>