title: Capture data from TextFormField on flutter for http POST request
body: <p>i am trying to make a login with flutter.
  I am consulting a web service.
  I want to send in the body of the Post request the username and the password from different TextFormField. how can i do that?
  Here is the code i've been working on.</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:device_id/device_id.dart';
  import 'package:http/http.dart' as http;
  
  import 'dart:async';
  import 'dart:convert';
  
  
  class SignIn extends StatefulWidget {
    @override
    _SignInState createState() =&gt; _SignInState();
  }
  
  class _SignInState extends State&lt;SignIn&gt; {
    Future&lt;String&gt; getData() async {
      final response = await http.post(
          Uri.encodeFull("The route i'm consulting),
          body: {
            "username": user,
            "password": password
          },
  </code></pre>
  
  <p>I want to retrieve the input texts from username and password TextFormField below in here</p>
  
  <pre><code>        headers: {
            "Accept": "application/json",
          });
      print(response.statusCode);
      print(response.body);
    }
  
    String _deviceid = 'Unknown';
    String user = '';
    String password = '';
  
    TextEditingController controller = new TextEditingController();
    TextEditingController controller2 = new TextEditingController();
  
    @override
    void dispose() {
      controller.dispose();
      controller2.dispose();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
       username = TextFormField(
  </code></pre>
  
  <p>This is the first TextFormField i want to retrieve to send it in the body of the request</p>
  
  <pre><code>      controller: controller,
        keyboardType: TextInputType.text,
        autofocus: false,
        decoration: InputDecoration(
            hintText: "Username",
            hintStyle: TextStyle(fontSize: 16.0),
            contentPadding: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 10.0),
            border:
                UnderlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
      );
      final password = TextFormField(
  </code></pre>
  
  <p>This is the second TextFormField i want to retrieve to send it in the body of the request</p>
  
  <pre><code>      controller: controller2,
        autofocus: false,
        obscureText: true,
        decoration: InputDecoration(
            hintText: "Password",
            hintStyle: TextStyle(fontSize: 16.0),
            contentPadding: EdgeInsets.fromLTRB(20.0, 25.0, 20.0, 10.0),
            border:
                UnderlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
      );
  
      final loginButton = Padding(
        padding: EdgeInsets.symmetric(vertical: 25.0),
        child: Material(
          borderRadius: BorderRadius.circular(30.0),
          shadowColor: Colors.blueAccent.shade100,
          elevation: 10.0,
          child: MaterialButton(
            minWidth: 200.0,
            height: 42.0,
            color: Colors.blueAccent,
            onPressed: (){
  
            },
            child: Text(
              "Login",
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
      );
  
      return Form(
        child: new Center(
          child: ListView(
              padding: EdgeInsets.only(left: 24.0, right: 24.0, top: 10.0),
              children: &lt;Widget&gt;[
                username,
                SizedBox(height: 8.0),
                password,
                SizedBox(height: 24.0),
                loginButton
              ]),
        ),
      );
    }
  }
  </code></pre>