Sorry can't able to show exact json file contents and API URL links
this is my json file contents
<b>Notice</b>: Undefined index: api_token in <b>/home/websitename/public_html/catalog/controller/startup/session.php</b> on line <b>8</b>{
"products": [
{
"product_id": "480",
"thumb": "https://exmaple.com/image/cache/catalog/401/a32-1000x1000-270x270.png",
"name": "Product Name",
"description": "Discription",
"special": false,
"tax": false,
"minimum": "1",
"rating": 0,
"href": "http://example.com/index.php?route=product/product&product_id=480"
},
]
}
this is my future function
Future<ProductModel> getProducts() async {
final String apiUrl = "https://www.example.com";
final http.Response response = await http.get(apiUrl);
var productModel;
try {
if (response.statusCode == 200) {
var jsonString = response.body;
var jsonMap = json.decode(jsonString);
productModel = ProductModel.fromJson(jsonMap);
}
} catch (Exception) {
print(Exception);
}
return productModel;
}
This is the API file from which we are getting data
<?php
class ControllerApiProduct extends Controller
{
public function index()
{
$this->load->language('api/cart');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$json = array();
$json['products'] = array();
$filter_data = array();
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float) $result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float) $result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = (int) $result['rating'];
} else {
$rating = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
$json['products'] = $data['products'];
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
here is my code of future builder
FutureBuilder<ProductModel>(
future: _productModel,
builder: (context, snapshot) {
if (snapshot.hasData) {
print(snapshot.data.products.length);
return GridView.builder(
itemCount: snapshot.data.products.length,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2),
itemBuilder: (context, index) {
return SingleProduct(
prodName: snapshot.data.products[index].name,
prodPicture: snapshot.data.products[index].thumb,
// prodOldPrice: productList[index]['oldPrice'],
prodPrice: snapshot.data.products[index].price,
prodDescription: snapshot.data.products[index].description,
prodId: snapshot.data.products[index].productId,
);
},
);
} else {
// return CircularProgressIndicator();
return CircularProgressIndicator();
}
});
My code is working but it is not able to get API data due to this notice <b>Notice</b>: Undefined index: api_token in <b>/home/example/public_html/catalog/controller/startup/session.php</b> on line <b>8</b>
is there a workaround to solve this.
the exact error is given below:
I/flutter (12559): FormatException: Unexpected character (at character 1)
I/flutter (12559): <b>Notice</b>: Undefined index: api_token in <b>/home/example/public_htm...
I/flutter (12559): ^