title: Post request to wordpress rest api in flutter
body: <p>I am stuck as being beginner. I want to post the rest api request in flutter using wordpress as backend.
  I can post the request in postman But don't know how to do this in flutter. As far as i write in flutter app.</p>
  
  <pre><code>import 'dart:async';
  import 'dart:convert';
  
  import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  
  Future&lt;JwtToken&gt; createjwtToken(String username,String password) async {
    final http.Response response = await http.post(
      'http://e4sftttpqshahryar.atwebpages.com/wp-json/jwt-auth/v1/token',
      headers: &lt;String, String&gt;{
        'Content-Type': 'application/json; charset=UTF-8',
      },
      body: jsonEncode(&lt;String, String&gt;{
        'username': username,
        'password': password,
      }),
    );
  
    if (response.statusCode == 201) {
      return JwtToken.fromJson(json.decode(response.body));
    } else {
      throw Exception('Failed to create album.');
    }
  }
  
  class JwtToken {
    String token;
    String userEmail;
    String userNicename;
    String userDisplayName;
  
    JwtToken(
        {this.token, this.userEmail, this.userNicename, this.userDisplayName});
  
    JwtToken.fromJson(Map&lt;String, dynamic&gt; json) {
      token = json['token'];
      userEmail = json['user_email'];
      userNicename = json['user_nicename'];
      userDisplayName = json['user_display_name'];
    }
  }
  
  void main() {
    runApp(MyApp());
  }
  
  class MyApp extends StatefulWidget {
    MyApp({Key key}) : super(key: key);
  
    @override
    _MyAppState createState() {
      return _MyAppState();
    }
  }
  
  class _MyAppState extends State&lt;MyApp&gt; {
    final TextEditingController _controller = TextEditingController();
    final TextEditingController _controller1 = TextEditingController();
    Future&lt;JwtToken&gt; _futureJwt;
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Create Data Example',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('Create Data Example'),
          ),
          body: Container(
            alignment: Alignment.center,
            padding: const EdgeInsets.all(8.0),
            child: (_futureJwt == null)
                ? Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: &lt;Widget&gt;[
                      TextField(
                        controller: _controller,
                        decoration: InputDecoration(hintText: 'Enter Usernam'),
                      ),
                       TextField(
                        controller: _controller1,
                        decoration: InputDecoration(hintText: 'Enter Password'),
                      ),
                      RaisedButton(
                        child: Text('Create Data'),
                        onPressed: () {
                          setState(() {
                            _futureJwt = createjwtToken(_controller.text,_controller1.text);
                          });
                        },
                      ),
                    ],
                  )
                : FutureBuilder&lt;JwtToken&gt;(
                    future: _futureJwt,
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return Text(snapshot.data.token);
                      } else if (snapshot.hasError) {
                        return Text("${snapshot.error}");
                      }
  
                      return CircularProgressIndicator();
                    },
                  ),
          ),
        ),
      );
    }
  }
  
  </code></pre>
  
  <p>This can accomplish in Post man as.I only wanted the highlighted value in my app <a href="https://i.stack.imgur.com/Kptpn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kptpn.png" alt="enter image description here"></a>.</p>
  
  <p><strong>I installed the Jwt plugin of the wordpress to make Jwt token. At the end my goal is to post the username and password in the **<a href="http://e4sftttpqshahryar.atwebpages.com/wp-json/jwt-auth/v1/token?username=shahryar&amp;password=e4sftttpq" rel="nofollow noreferrer">http://e4sftttpqshahryar.atwebpages.com/wp-json/jwt-auth/v1/token?username=shahryar&amp;password=e4sftttpq</a></strong> So I can get Jwt token and make the function Login,Logout and update user and post information in the wordpress Site.**</p>