title: Flutter get selected value from dropdownmenu from other class
body: <p>I want to get the currently selected value from the dropdown menu in another class of my Flutter web app. As the dropdownValue variable is local, it is not usable outside the scope of its class.
  Here is what I tried:</p>
  <pre><code>class _DPWidgetState extends State &lt; DPWidget &gt; {
  String dropdownValue = '1';
  @override
  Widget build(BuildContext context) {
      return DropdownButton &lt; String &gt; (
          value: dropdownValue,
          icon: Icon(Icons.arrow_downward),
          iconSize: 24,
          elevation: 16,
          style: TextStyle(color: Colors.deepPurple),
          underline: Container(
              height: 2,
              color: Colors.deepPurpleAccent,
          ),
          onChanged: (String newValue) {
              setState(() {
                  dropdownValue = newValue;
              });
          },
          items: &lt; String &gt; ['1', '2', '3']
          .map &lt; DropdownMenuItem &lt; String &gt;&gt; ((String value) {
              return DropdownMenuItem &lt; String &gt; (
                  value: value,
                  child: Text(value),
              );
          }).toList(),
      );
  }
  }
  </code></pre>