I want to using php code to do scanning barcode but i just get the barcode number only. How i can do the php code and how to extract the data in flutter.My php code like this
<?php
error_reporting(0);
include_once ("dbconnect.php");
$code=$_POST['code'];
$encoded_string = $_POST["encoded_string"];
$decoded_string = base64_decode($encoded_string);
if (isset($code)){
$sql = "SELECT * FROM PRODUCT WHERE CODE ='$code'";
}
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$response["product"] = array();
while ($row = $result->fetch_assoc())
{
$productlist = array();
$productlist["id"] = $row["ID"];
$productlist["name"] = $row["NAME"];
$productlist["price"] = $row["PRICE"];
$productlist["stock"] = $row["STOCK"];
$productlist["description"] = $row["DESCRIPTION"];
$productlist["code"] = $row["CODE"];
array_push($response["product"], $productlist);
}
echo json_encode($response);
}
else
{
echo "nodata";
}
?>
I have try to extract data in flutter,but it just pass the barcode number only.this is how i try to call/pass the data from php.
Future<Product> getProduct()async{
String code;
await http.post("https://smileylion.com/easyshopping/php/getproducts.php",body:{
"code":code
})
.then((response){
print(response.body);
if(response.body=="nodata"){
titlecenter= "No product found";
setState(() {
productdata =null;
});
} else{
setState(() {
var extractdata = json.decode(response.body);
productdata = extractdata["product"];
});
}
}).catchError((err) {
print(err);
});
}
If any wrong or something needs to add? I am quite new to Flutter, and I am currently working on an application that needs barcode reading.