fetchProduct method

dynamic fetchProduct({
  1. required dynamic Proid,
})

Implementation

fetchProduct({required Proid}) async {
  String request_api = 'products';

  if (Proid != null) {
    request_api = '$request_api/$Proid';
  }

// ApiService is another class in which http package functions are defined ,
// it'll make query get response and will pass response as it is if request is successful (i.e. Status Code == 200)
// or else if failed it'll throw exception with response recieved.
  Response res = await ApiServices()
      .getRequest(request_api, baseUrl, consumerKey, consumerSecret);
  // since complete response is returned , response body will be decoded to get json object.
  var decoded_data = json.decode(res.body);

// A model class for Product is created and will used by devloper to access and display or use data in whatever way,
// this function will return List of type Product model .
  Product parsedProduct = Product.fromJson(decoded_data);

  return parsedProduct;
}