1

This is likely a mistake and is unsupported. If you're in this situation, consider passing a key unique to each individual constructor.

Above is the error which reflects on Running the code with a flutter widget as a child:-

    GridView.builder(
      padding: const EdgeInsets.all(10.0),
      itemCount: products.length,
      itemBuilder: (ctx, i) => ChangeNotifierProvider.value(
        value: products[i],
        child: ProductItem(
            ),
      ),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: 3 / 2,
        crossAxisSpacing: 10,
        mainAxisSpacing: 10,
      ),
    )
Harsh J
  • 413
  • 1
  • 4
  • 15

1 Answers1

4

This situation can be tackled by using keys as specified:-

    GridView.builder(
      padding: const EdgeInsets.all(10.0),
      itemCount: products.length,
      itemBuilder: (ctx, i) => ChangeNotifierProvider.value(
        key: Key("item$i"),
        value: products[i],
        child: ProductItem(
            ),
      ),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: 3 / 2,
        crossAxisSpacing: 10,
        mainAxisSpacing: 10,
      ),
    )
Harsh J
  • 413
  • 1
  • 4
  • 15