Skip to main content

Get One Product

There is some cases when you will need to fetch only one Product, without getting a whole List<Product>, for this you can use the one() method with the product Id, like this :

Using await/async :

Product oneProduct = await YouCan.instance.products.one("YOUR PRODUCT ID");

Using A FutureBuilder :

FutureBuilder<List<Product>>(
future: YouCan.instance.products.all(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text(snapshot.data);
} else if (snapshot.hasError) {
return Text("Error: ${snapshot.error}");
} else {
return CircularProgressIndicator();
}
},
),