In login API it returns response, I want to get the response in button onclick and print it.

How can I do this?

   onTap: () async => {
           await propertyBloc.fetchAllCategory();

           <some code>


Solution 1: Alok

To do your task, you must need to do these things:

  1. Call the API and get the response
  2. Print on Tap

1. To get the response you must import the http package, and then do this:

Make a method which gives out the response:

import 'package:http/http.dart' as http;

Future<http.Response> fetchData() async {
  final response =
      await http.get(your_url);

  if (response.statusCode == 200) {
    // If server returns an OK response, parse the JSON.
    return json.decode(response.body);
  } else {
    // If that response was not OK, throw an error.
    throw Exception('Failed to load post');


//Call the function on tap of the button, which will return the data
onTap: (){this.fetchData();}

Hope that helps. :)