I’ve tried to call the data from the database and I’ve used Node-red to be the connection between my flutter project and database. However, there is no connection between my project and database. This’s my code.
class Products {
int product_id;
String real_id;
String product_name;
String detail;
double price;
String picture;
Products(
{this.product_id,this.real_id, this.product_name, this.picture, this.price, this.detail});
Products.fromJson(Map<String, dynamic>json){
product_id=json['product_id'];
real_id=json['real_id'];
product_name=json['product_name'];
detail=json['detail'];
price=json['price'];
picture=json['picture'];
}
Map<String, dynamic> toJson(){
final Map<String, dynamic> data = new Map<String, dynamic>();
data['product_id'] =this.product_id;
data['real_id'] = this.real_id;
data['product_name']=this.product_name;
data['detail'] = this.detail;
data['price']=this.price;
data['picture']=this.picture;
return data;
}
}
Future<Products> getProductInfo(String product_id, String real_id,String product_name,String detail,double price,String picture) async{
String url="http://IP address/getProductInfo";
var result = await http.post(url,body:
{"product_id":product_id,
"real_id":real_id,
"product_name":product_name,
"detail":detail,
"price":price,
"picture":picture
});
if(result.statusCode==200){
print(result.body);
var json_object = json.decode(result.body);
return Products.fromJson(json_object);
}
}
and the code below is the code I’ve used to display the data.
class ProductDetailInfo extends StatelessWidget {
List<Products> p_detail;
ProductDetailInfo({this.p_detail});
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: p_detail.length,
itemBuilder: (BuildContext context, int index){
return Container(
child: Text(p_detail[index].product_name,
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Baloo2',
fontSize: 25,
color: Colors.white)),
);
}
);
}
}