title: How can I get token response with username and password textfields? dart/flutter
body: <p>I'm kind of new to <code>rest api</code> and <code>flutter</code>.
  I wanna login with the username and password and get the token response.
  How can I get the username and password from the text field for <code>authorization</code>?
  I'm also not sure about the auth code is correct?</p>
  <pre><code>imports
  
  class HomePage extends StatefulWidget {
    @override
    State&lt;StatefulWidget&gt; createState() {
      return _HomePageState();
    }
  }
  
  class _HomePageState extends State&lt;HomePage&gt; {
  
    final  usernameController = TextEditingController();
    final  passwordController = TextEditingController();
  
  Future&lt;String&gt; authorization() async {
      var request = http.MultipartRequest(
          'POST', Uri.parse('url'));
      request.fields.addAll({
        'grant_type': 'info',
        'client_id': 'info',
        'username': username,
        'password': password,
      });
  
      http.StreamedResponse response = await request.send();
  
      if (response.statusCode == 200) {
        Map&lt;String, dynamic&gt; auth =
            jsonDecode(await response.stream.bytesToString());
  
        return auth['access_token'];
      } else {
        return &quot;&quot;;
      }
    }
  
    void _setText() {
      setState(() {
        username = usernameController.text;
        password = passwordController.text;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Login'),
          backgroundColor: Colors.green,
        ),
        body: Column(
          children: [
            Padding(
              child: TextField(
                decoration: InputDecoration(labelText: 'username'),
                controller: usernameController,
              ),
            ),
            Padding(
              child: TextField(
                decoration: InputDecoration(labelText: 'password'),
                controller: passwordController,
              ),
            ),          
            RaisedButton(
              onPressed: _setText,
              child: Text('Login'),
            ),
          ],
        ),
      );
    }
  }
  </code></pre>