Skip to main content

Goods

Default implementation​

To integrate Goods in your stories, you need to:

  1. Add "Goods" widget to a story in the console editor;
  2. Set goods item appearance from AppearanceManager:
await AppearanceManager.instance.setGoodsItemAppearance(GoodsItemAppearance());
  1. Realize method from InAppStoryManager:
void setUpSkus() {
InAppStoryManager.instance.setGetSkusCallback((skus) async {
// get goods info from your App
getGoods();

final listOfGoods = <GoodsItemData>[];
for (var sku in skus) {
final good = widget.goods.firstWhere(
(element) => element.sku == sku,
orElse: () =>
GoodsItemData(
sku: sku,
//item sku
title: 'Title$sku',
// item title for cell
description: 'Desc$sku',
// item subtitle for cell
price: '${Random().nextInt(1000) + 500}',
// item price value
oldPrice: '${Random().nextInt(500)}', // item discount value
),
);
listOfGoods.add(
GoodsItemData(
sku: good.sku ?? '',
price: good.price,
oldPrice: good.oldPrice,
image: good.image,
description: good.description,
title: good.title,
),
);
}
return listOfGoods;
});
}

Customization​

Using GoodsItemAppearance class you can customize appearance of Goods widget

Parameters​

NameTypeDescription
itemBackgroundColorColorbackground color of item
widgetBackgroundColorColorbackground color of widget
itemMainTextColorColorgoods item text color
itemCornerRadiusintgoods item corner radius
itemOldPriceTextColorColorgoods item discount text color
itemTitleTextSizeinttitle text size
itemDescriptionTextSizeintdescription text size
itemPriceTextSizeintprice text size
itemOldPriceTextSizeintdiscount text size
widgetBackgroundHeightintheight of Goods widget
closeButtonImageStringpath to icon asset (png, jpg, jpeg)
closeButtonColorColorcolor of default icon close button

Events​

To listen item selected callback, you need to add IASGoodItemSelectedCallback mixin to your state widget:

Migration

Starting with version 0.11.0, IASGoodItemSelectedCallback receives the GoodsItemData domain model instead of GoodsItemDataDto. In GoodsItemData, use item.description to access the product description. See the migration guide.

class _ExampleState extends State<Example> with IASGoodItemSelectedCallback {

Widget build(BuildContext context) {
return const Placeholder();
}


Future<void> goodsItemSelected(GoodsItemData item) async {
// you can close story reader before action with good
await InAppStoryManager.instance.closeReaders();
// any code here
}
}