title: Call FutureBuilder from RaisedButton
body: <p>i would love to call the Future <strong>fetchPost</strong> from a <strong>RaisedButton</strong> or in other words i don't wan't the FutureBuilder to do anything until i click the button, i tried calling fetchPost from the button but it won't work and I'm stuck. </p>
  
  <p>PS: I used the example from this page <a href="https://flutter.io/cookbook/networking/fetch-data/" rel="nofollow noreferrer">https://flutter.io/cookbook/networking/fetch-data/</a></p>
  
  <p>Your help is appreciated.</p>
  
  <pre><code>import 'dart:async';
  import 'dart:convert';
  
  import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  
  Future&lt;Post&gt; fetchPost() async {
    final response =
    await http.get('https://jsonplaceholder.typicode.com/posts/1');
  
    if (response.statusCode == 200) {
      // If the call to the server was successful, parse the JSON
      return Post.fromJson(json.decode(response.body));
    } else {
      // If that call was not successful, throw an error.
      throw Exception('Failed to load post');
    }
  }
  
  class Post {
    final int userId;
    final int id;
    final String title;
    final String body;
  
    Post({this.userId, this.id, this.title, this.body});
  
    factory Post.fromJson(Map&lt;String, dynamic&gt; json) {
      return Post(
        userId: json['userId'],
        id: json['id'],
        title: json['title'],
        body: json['body'],
      );
    }
  }
  
  class FirstFragment extends StatelessWidget {
    FirstFragment(this.usertype,this.username);
    final String usertype;
    final String username;
  
    @override
    Widget build(BuildContext context) {
      final ThemeData theme = Theme.of(context);
      final Size screenSize = MediaQuery.of(context).size;
  
      return new SingleChildScrollView(
        padding: new EdgeInsets.all(5.0),
        child: new Padding(
          padding: new EdgeInsets.symmetric(vertical: 0.0, horizontal: 0.0),
          child: new Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: &lt;Widget&gt;[
              new Container(
                child: new RaisedButton(
                  child: new Text('Call'),
                  onPressed: (){
                    fetchPost();
                  },
                ),
              ),
              new Container(
                child: FutureBuilder&lt;Post&gt;(
                  future: fetchPost(),
                  builder: (context, snapshot) {
                    if (snapshot.hasData) {
                      return Text(snapshot.data.title);
                    } else if (snapshot.hasError) {
                      return Text("${snapshot.error}");
                    }
                    // By default, show a loading spinner
                    return CircularProgressIndicator();
                  },
                )
              )
            ],
          ),
        ),
      );
  
    }
  }
  </code></pre>