title: Flutter code executed before button clicked
body: <p>I have a ListTile (in the drawer), which when clicked, goes to a new screen and in that screen the user can choose from a number of (using a for loop) IconButtons (which are in a ListView), but the function which is to be executed when one taps the button is actually executed when the user is sent to the choosing screen (when he/she clicked the ListTile) and as a result the function (which by the way opens another screen) gets executed the same amount of times as there are IconButtons in my ListView and before they are clicked.</p>
  
  <p>For more details see the sourcecode:</p>
  
  <p>When the ListTile is clicked:</p>
  
  <pre><code>              setState(() {
                  goDownloads(files);
                });
  </code></pre>
  
  <p>Function for opening to the new screen:</p>
  
  <pre><code>goDownloads(List&lt;File&gt; files) async {
    for (int n = 0; n &lt; files.length; n++) {
      String url = files[n].path;
      Widget container = new Container(
          child: new Row(
              children: &lt;Widget&gt;[
                new IconButton(
                  onPressed: openBook(url),//This is the code that gets executed before it's supposed to
                  icon: new Icon(Icons.open_in_browser),
              ),
  ...
            ]
        )
    );
    dlbooks.add(container);
  }
  setState(() {
    Navigator.of(context).push(new MaterialPageRoute&lt;Null&gt;(
      builder: (BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(title: new Text('My Page')),
          body: new Center(
            child: new ListView(
                children: dlbooks
            ),
          ),
        );
      },
    ));
  });
  }
  </code></pre>
  
  <p>I also have the full code in a main.dart file, though I don't recommend it since it's not well written, I'm still a noob. <a href="https://pastebin.com/vZapvCKx" rel="nofollow noreferrer">https://pastebin.com/vZapvCKx</a>
  Thanks in advance!</p>