Change state of Flutter widget from outside it's State class : <p>I created a DropdownButton as a StatefulWidget. The class is called MyDropDown, with the corresponding state called MyDropDownState.</p>

<p>I created a reset function in the MyDropDownState class:</p>

<pre><code>void reset(){
    setState((){
        _selection = null;
    });
}
</code></pre>

<p>which will set the selection to null and set the state of the dropdown, effectively resetting the dropdown.</p>

<p>The core of the problem is I have to call this function when an IconButton on the AppBar is pressed. I have tried multiple ways and just can't get access to the state of the MyDropDown class I created.</p>

<p>This is the code of MyDropDown and it's State, simplified:</p>

<pre><code>class MyDropDown extends StatefulWidget {

  final Map&lt;String, String&gt; _itemMap;

  MyDropDown(this._itemMap);

  @override
  MyDropDownState createState() =&gt; new MyDropDownState();
}

class MyDropDownState extends State&lt;MyDropDown&gt; {

  String _selection;

  void reset(){
    setState((){
      _selection = null;
    });
  }

  @override
  void initState() {
    _selection = null;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
      return new DropdownButton(
          value: _selection,
          //getDropItems builds dropdown items
          items: getDropItems(widget._itemMap),
          onChanged: (s) {
            setState(() {
              _selection = s;
            });
          },
      );
  }

}
</code></pre>

<p>In my main page, I create a new MyDropDown</p>

<pre><code>final MyDropDown cityDropdown = new MyDropDown(cityLookup);
</code></pre>

<p>then this is the AppBar (inside a Scaffold) that holds the IconButton I want to press to reset the Dropdown.</p>

<pre><code>appBar : new AppBar(
    title: new Text('Filter Jobs'),
    actions: &lt;Widget&gt;[
      new IconButton(
          icon: new Icon(Icons.refresh),
          onPressed: () {
            print('Reset dropdowns');
            //this is where I would call reset() on cityDropdown's state, if I could figure out how to get to it :/
          },
      ),
    ],
  ),
</code></pre>
