# Customize product card on videos using the custom view (Flutter)

The Firework Flutter SDK allows providing a custom view for the product card. This way, it is possible to have full control over the look and feel of the product card.

### iOS

1. Create a custom view class to implement the `ProductCardViewRepresentable` protocol.

<pre class="language-swift"><code class="lang-swift">import FireworkVideo

<strong>class CustomProductView: UIView, ProductCardViewRepresentable {
</strong>    lazy var label: UILabel = UILabel(frame: .zero)
    lazy var detailsLabel: UILabel = .init(frame: .zero)
    
    /**
     Called before a product card is reused.
     - Note: This is an opportunity to clean up the product card UI elements
     */
     func prepareForReuse() {
         label.text = ""
         detailsLabel.text = ""
     }
  
     /**
      Called before a product card will be displayed on screen
      - Important: It is best to avoid network calls when this method is invoked. The product card is just moments from being rendered and network calls
      at this stage would provide a degraded user experience. Please use the hydration API to perform any product data updates.
      - Note: This is the opportunity to update the product card UI with product specific details
      - Parameters:
       - product: The product details associated to the view that will be displayed
       - video: The details of the video the product is associated with.
     */
     func updateViewForProduct(_ product: ProductCardDetails, associatedTo video: VideoDetails) {
         label.text = product.name
         detailsLabel.text = "$\(product.price.amount)"
     }
}
</code></pre>

2. Call `FireworkVideoSDK.shopping.productCardViewType = CustomProductView.self` at the appropriate place, such as `application(:, didFinishLaunchingWithOptions:) -> Bool`.

```swift
import FireworkVideo

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    FireworkVideoSDK.shopping.productCardViewType = CustomProductView.self
    
    return true
}
```

### Android

To enable this feature on Android, the host app should pass the following product card configuration:

```kotlin
FireworkSdk.shopping.setShoppingViewOptions(
    ShoppingViewOptions(
        theme = getProductCardsTheme(),
        productCardsOptions = ProductCardsOptions.Custom(
            widthPx = width,
            heightPx = height,
            spaceBetweenItems = spaceBetweenItems,
            cardViewStartEndPadding = padding,
            customViewProvider = { MyCustomProductCard(this) },
        ),
    ),
)
```

**Provide a view for the custom product card.** To pass a view for the custom product card, the host app should provide a `customViewProvider` parameter. This parameter is a factory function with the following signature:

```kotlin
val customViewProvider: () -> FwProductCardView
```

The function returns implementation of `FwProductCardView`. `FwProductCardView` is an abstract class with a single abstract method that gets called when the card is inflated by Firework Flutter SDK.

```kotlin
    abstract fun bind(product: ProductCardDetails, videoInfo: VideoInfo)
```

`ProductCardDetails` and `VideoInfo` contain information about the product and the video related to the product card. Here is an example of `FwProductCardView` implementation (initialization of the fields is omitted):

```kotlin
class MyCustomProductCard @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyle: Int = 0,
) : FwProductCardView(context, attrs, defStyle) {
    
    init {
        inflate(context, R.layout.custom_product_card_item, this)
    }

    override fun bind(product: ProductCardDetails, videoInfo: VideoInfo) {
        title.text = product.productTitle
        price.text = "${product.price?.amount ?: 0.0} ${product.price?.currencyCode}"
        Glide.with(image.context)
            .load(product.productImageUrl)
            .placeholder(R.drawable.ic_product_placeholder)
            .error(R.drawable.ic_product_placeholder)
            .into(image)
    }
}
```

**Width and height of the custom product card.** The width and height of the custom product card should be specified in pixels. The Firework Flutter SDK can limit the size of the product card if it is not respecting the safe zone. Details of the Safe Zone Specifications for Firework Videos can be found here - <https://help.firework.com/safe-zone-specifications-for-firework-videos>

**Clickable elements on the custom product card.** Firework Flutter SDK do not allow to have clickable elements on the custom product card. If the custom product card has clickable elements, the click will be intercepted by the Firework Flutter SDK and the default behaviour will be triggered.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.firework.com/firework-for-developers/flutter-sdk/integration-guide-v2/customization/shopping-configurations-flutter/customize-product-card-on-videos-using-the-custom-view-flutter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
