Created
October 24, 2021 16:16
-
-
Save perymerdeka/3adfb13543897f6097574debec912fde to your computer and use it in GitHub Desktop.
Product Grid for HomeScreen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:provider/provider.dart'; | |
import 'package:providers/models/product.dart'; | |
import 'package:providers/providers/products.dart'; | |
import 'package:providers/widgets/product_item.dart'; | |
class ProductGrid extends StatelessWidget { | |
const ProductGrid({ | |
Key? key, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
// Provider | |
final ProductProvider productData = Provider.of<ProductProvider>(context); | |
// getting product of product data | |
final List<Product> allProduct = productData.products; | |
return GridView.builder( | |
padding: const EdgeInsets.all(10.0), | |
itemCount: allProduct.length, | |
itemBuilder: (ctx, i) => ProductItem( | |
allProduct[i].id, | |
allProduct[i].title, | |
allProduct[i].imageUrl, | |
), | |
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( | |
crossAxisCount: 2, | |
childAspectRatio: 3 / 2, | |
crossAxisSpacing: 10, | |
mainAxisSpacing: 10, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment