Flutter Login through API


After Successful Login, I am getting User_id and User_type
I want to access the User_id and User_type.
By Using User_type,I want to log in the supervisor or Promoter

  Future postMethod() async {
    var api = Uri.parse("https://demo.likemyfiles.com/DS/api/auth/otp");
    Map mapeddate ={
      final response = await http.post(api, body: mapeddate);

Output Will be:-


Now I want to Access this user_type to login into the Supervisor and if the User_type:-2, I want to log in to the Promoter’s Window.

Also, I want to store User_id into another variable to Show it on the screen.

enter image description here


You can decode response.body to get user-type. Then apply if-else logic.

  var res = json.decode(response.body);
   if(res['user_type'] == "1"){
      // supervisor logic
     // promotor window logic

Also you get can user_id by using res['user_id'].

Answered By – John Joe

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *